c++ simple code 3ms


  • 0
    V
    class Solution {
    public:
        int removeElement(vector<int>& nums, int val) {
            int size = nums.size();
            int length = 0;
            
            for (vector<int>::iterator it = nums.begin(); it != nums.end(); ++it)
            {
                if (*it == val)
                {
                    nums.erase(it--);
                    continue;
                }
                length++;
            }
            
            return length;
        }
    };
    

Log in to reply
 

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