A short C++ code with constant extra space

  • 0
    class Solution 
        int removeElement(vector<int>& nums, int val) 
            int len = nums.size();
            int i = 0;
            while(i < len)
                nums[i] == val? (nums[i] = nums[--len]): ++i;
            return len;

Log in to reply

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