Create 027-Remove Element.md

This commit is contained in:
唐树森 2018-09-01 18:54:03 +08:00 committed by GitHub
parent 4a985b9666
commit 8f17821712
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

15
027-Remove Element.md Normal file
View File

@ -0,0 +1,15 @@
# 思路
类似第26题, 用count记录非val的个数从前往后遍历如果值为val则跳过否则令nums[count并=nums[i]并自增count
# 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;
}
};
```