5 lines. O(n)


  • 0
    T

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


Log in to reply
 

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