9 line C++ solution


  • 0
    I
    class Solution {
    public:
        int removeElement(vector<int>& nums, int val) {
            int k = 0, i;
            for(i = 0; i < nums.size(); ++i)
                if(nums[i] != val) nums[k++] = nums[i];
            return k;
        }
    };
    

Log in to reply
 

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