Solution in C with memory manipulation

  • 0
    int removeDuplicates(int A[], int n) {
    int new_size = n;
    for(int i = 1; i < n; ++i){
        if(A[i - 1] == A[i]){
            memmove(&A[i - 1], &A[i], ((n-i)*sizeof(int)));
            A[n - 1] = 999 + new_size;
    return new_size;}

    Here is my solution in C with memove(). I think it's an O(n ^ 2) solution but I am not sure about how long will memmove() take. It seems that it's very fast. I use no extra space. However, memmove() do need a buffer for moving memory around. Hope you enjoy the solution.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.