-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path80.java
More file actions
38 lines (37 loc) · 1.04 KB
/
80.java
File metadata and controls
38 lines (37 loc) · 1.04 KB
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
37
38
__________________________________________________________________________________________________
sample 0 ms submission
class Solution {
public int removeDuplicates(int[] nums) {
if (nums == null)
return 0;
if(nums.length < 3)
return nums.length;
/*
1,1,1,2,2,3
i j
*/
int i = 1, j = 2;
while (j < nums.length) {
if (nums[j] == nums[i] && nums[i] == nums[i-1]) {
j++;
} else {
i++;
nums[i] = nums[j];
j++;
}
}
return i+1;
}
}
__________________________________________________________________________________________________
sample 35436 kb submission
class Solution {
public int removeDuplicates(int[] a) {
int n=a.length,i=0;
for (int k : a)
if (i < 2 || k > a[i - 2])
a[i++] = k;
return i;
}
}
__________________________________________________________________________________________________