Skip to content

Commit dcb7732

Browse files
80. Remove Duplicates from Sorted Array II (java)
1 parent 51cfa83 commit dcb7732

File tree

1 file changed

+15
-0
lines changed
  • solution/0080.Remove Duplicates from Sorted Array II

1 file changed

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

0 commit comments

Comments
 (0)