Skip to content

Commit 9d91f11

Browse files
committed
Create 0080-remove-duplicates-from-sorted-array-ii.java
1 parent 94bbd8b commit 9d91f11

File tree

1 file changed

+20
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)