Why my C++ code not accepted while run correctly on my machine


  • -1
    L
    class Solution {
    public:
        int removeElement(vector<int>& nums, int val) {
            vector<int>::iterator iter = find(nums.begin(), nums.end(), val);
            int count = 0;
            while(iter != nums.end()) {
                nums.erase(iter);
                iter = find(nums.begin(), nums.end(), val);
                count ++;
            }
            return count;
        }
    };
    
    the input and output like this:
    Input:
    [1], 1
    Output:
    [1]
    Expected:
    []

Log in to reply
 

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