0ms C simple solution


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

Log in to reply
 

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