C solution, O(n) time and O(1) space (0ms)


  • 1
    B
    int removeElement(int* nums, int numsSize, int val) {
        int remove = 0;
        
        for(int i = 0; i < numsSize; ++i)
        {
            if(nums[i] == val) ++remove;
            else
                nums[i - remove] = nums[i];
        }
        return numsSize - remove;
    }

Log in to reply
 

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