C++ , 3ms


  • 0
    B

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

          return leng1;
    }
    

    };


Log in to reply
 

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