LeetCode/solutions/27. Remove Element.md
2019-09-13 23:08:41 +08:00

16 lines
412 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 思路
类似第26题, 用count记录非val的个数从前往后遍历如果值为val则跳过否则令nums[count并=nums[i]并自增count
# C++
``` C++
class Solution {
public:
int removeElement(vector<int>& nums, int val) {
int count = 0;
for(int i = 0; i < nums.size(); i++){
if(nums[i] != val) nums[count++] = nums[i];
}
return count;
}
};
```