5 line C++ code


  • 0
    Y
    public:
        int removeElement(vector<int>& nums, int val) {
            auto itr_new = nums.begin();
            
            for (int x : nums) {
                if (x != val)
                    *itr_new++ = x;
            }
            return distance(nums.begin(), itr_new);
        }
    };

Log in to reply
 

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