My accepted simple solution in C++,Any advising?


  • 0
    K
    class Solution {
    public:
        int removeElement(int A[], int n, int elem) 
        {
            int len=0;
            for(int i=0;i<n;i++)
            {
                while((i<n)&&(A[i]==elem))
                    i++;
                if(i<n)
                    A[len++]=A[i];
            }
            return len;
        }
    };

Log in to reply
 

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