[LeetCode]移除元素

版权声明:本文为本人原创文章,未经博主允许不得转载。 https://blog.csdn.net/m0_37316917/article/details/87882135

题目

 

代码 

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

猜你喜欢

转载自blog.csdn.net/m0_37316917/article/details/87882135
今日推荐