five lines simple O(n) c++ solution


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

Log in to reply
 

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