【LeetCode】27. 移除元素

移除指定元素

  • 时间复杂度 O(n)
  • 空间复杂度 O(1)
class Solution {
public:
    int removeElement(vector<int>& nums, int val) {
        int fast,low;
        for(fast = 0,low = 0; fast < nums.size(); fast++) {
            if(nums[fast] != val) {
                nums[low] = nums[fast];
                low++;
            }
        }
        return low;
    }
};
posted @ 2023-02-27 14:39  小超不挑食  阅读(15)  评论(0编辑  收藏  举报