-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleetcode80.java
More file actions
36 lines (34 loc) · 934 Bytes
/
Copy pathleetcode80.java
File metadata and controls
36 lines (34 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package leetcode;
public class leetcode80 {
public int removeDuplicates(int[] nums) {
if(nums.length<=2) return nums.length;
int len=nums.length;
int cur=nums[0];
int cur_num=1;
int result=1;
for(int i=1;i<len;){
if(i<len&&cur==nums[i]&&cur_num<2){
cur_num++;
result++;
i++;
}else if(i<len&&cur==nums[i]&&cur_num==2){
for(int j=i;j<nums.length-1;j++){
nums[j]=nums[j+1];
}
len--;
}
if(i<len&&cur!=nums[i]){
cur=nums[i];
cur_num=1;
result++;
i++;
}
}
return result;
}
public static void main(String[] args) {
new leetcode80().removeDuplicates(new int[]{
0,0,1,1,1,1,2,3,3
});
}
}