移除指定元素
- 时间复杂度 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;
}
};
标签:27,nums,int,fast,low,移除,LeetCode
From: https://www.cnblogs.com/zjacky/p/17159608.html