LeetCode 27 Remove Element

Tag: 数组类题目 LeetCode Posted on 2022-02-13 19:43:47 Edited on 2022-02-13 20:07:09 Views: 155

概述

https://leetcode.com/problems/remove-element/

快慢指针

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

未经允许,禁止转载,本文源站链接:https://iamazing.cn/