Ad
  • Custom User Avatar

    BIG O(n) BABY. LETS GO!!!!!!!!!!!!!!!

  • Custom User Avatar

    low amount of lines but time complexity higher than mine :P

  • Custom User Avatar

    Even tho you most likely won't see this, but hate to break it to you - not everyone cares about coding principles - if you can do something in one line of code and it is not very unreadable, a lot of people will do just that and most people are fine with that.
    In production and development codebases for huge apps - of course its better to keep things simple and readable, but if you can condense two or three loops to just 1-2 lines, but then explain the choice in documentation - thats way better.

  • Custom User Avatar

    g for global, which is used for pattern literals right?
    and i for CASE-iNSENSETIVE?

  • Custom User Avatar

    This is literally me when I started coding.
    Comments:)

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    wow bit shifting so clever

  • Custom User Avatar

    if you are wondering why i calculate some abstract "len", its cause i am sleep deprived RIGHT NOW, but you know...
    C AIN'T WAITING

  • Custom User Avatar

    The String.split(String s) splits the string into an array of strings in places where there is s in the original string. So you have something like "hello world!", and if you do "hello world!".split(" ") it will split the string into an array like this:{"hello", "world!"}
    Then with the [0] he is accessing the first element of the array. 0 is the first element in Java and you access array elements by an index with square brackets, remember!

  • Custom User Avatar

    Thanks for your explanation.

    I saw the comment, but I forgot the size is specified in the declaration, so I basically was like "you give me an array, but the memory is not allocated yet", which is wrong, thanks!

    I am doing codewars fundamentals only right now, in between reading "The C Programming Language", and I am only on chapter 2, so yeah I know nothing about how all this stuff works.

  • Custom User Avatar

    @lowlight

    your malloc() doesnt do anything, it just leaks memory. it is overwritten by the first pass of your for loop. Re-assigning integers inside your function will not affect its value outside of your function. Besides, your are assigning an address to an integer, the compiler most likely warned you about this:

    warning: assignment to ‘int’ from ‘void *’ makes integer from pointer without a cast [-Wint-conversion]
    

    This is because *integers points to the first element of the array; i.e. to an int. But even if you had written integers = malloc(...), this would make no sense, because the caller would not see the change: through the function call your are given a copy of the address of integers. If you wanted to change what integers point to, your function would need to take an int **, not an int *.

    its not specified

    It is specified by a comment in the initial code, which is still there in your solution:

    assign function results to provided array

  • Custom User Avatar

    bruh. its not specified so i calculated the size and allocted that much with malloc

  • Custom User Avatar

    integers is already preallocated by the tests and it is ensured that it is big enough to hold the result.
    The ++ just moves the pointer forward.

  • Custom User Avatar

    are you dynamically adding more space to the array with the *integers++?

  • Custom User Avatar

    Базар брааза

  • Loading more items...