Skip to content

Commit 973f65e

Browse files
authored
Merge pull request gzc426#29 from zchoas/master
from张小胖
2 parents 09d677c + c988086 commit 973f65e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

2019.11.25-leetcode80/张小胖.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
int removeDuplicates(vector<int>& nums) {
4+
if (nums.size() <= 2) return nums.size();
5+
int end = 2; //end是最终的长度
6+
for (int i = 2; i < nums.size(); i++) {
7+
if (nums[end - 2] != nums[i]) { //对比这两个数是否相等即可
8+
nums[end++] = nums[i];
9+
}
10+
}
11+
return end;
12+
}
13+
};

0 commit comments

Comments
 (0)