Skip to content

Commit 8976cf8

Browse files
Sam  LuoSam  Luo
Sam Luo
authored and
Sam Luo
committed
create solution for 0080-remove-duplicates-from-sorted-array-ii
1 parent 2c10e7f commit 8976cf8

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Time Complexity: O(n);
3+
* Space Complexity: O(1);
4+
*/
5+
6+
class Solution {
7+
public int removeDuplicates(int[] nums) {
8+
int count = 1;
9+
int index1 = 0;
10+
for(int i = 1; i < nums.length; i++){
11+
if(nums[i] != nums[index1]){
12+
count = 1;
13+
index1 ++;
14+
nums[index1] = nums[i];
15+
}else{
16+
count ++;
17+
if(count <= 2){
18+
index1 ++;
19+
nums[index1] = nums[i];
20+
}
21+
};
22+
};
23+
return index1 + 1;
24+
}
25+
}
26+

0 commit comments

Comments
 (0)