Skip to content

Commit f7aa25f

Browse files
authored
Create 80. Remove Duplicates from Sorted Array II
1 parent 5730fe5 commit f7aa25f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
public class Solution {
2+
public int removeDuplicates(int[] nums) {
3+
int cur = 1;
4+
int count = 1;
5+
for(int i = 1; i < nums.length; i++){
6+
if(nums[i] == nums[i - 1]){
7+
count ++;
8+
if(count <= 2){
9+
nums[cur ++] = nums[i];
10+
}
11+
}else{
12+
nums[cur ++] = nums[i];
13+
count = 1;
14+
}
15+
}
16+
return cur;
17+
}
18+
}

0 commit comments

Comments
 (0)