Simple and easy C++ solution


  • 1
    D
    class Solution {
    public:
        int removeElement(int A[], int n, int elem) {
            int j=0;
            for (int i=0; i<n; i++)
            {
                if(A[i]!=elem)
                {
                    A[j++]=A[i];
                }
            }
            return j;
        }
    };

  • 0
    T

    If there are more than one number that equals to elem,the length of the A is changing.


Log in to reply
 

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