-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_0080.java
More file actions
29 lines (27 loc) · 751 Bytes
/
_0080.java
File metadata and controls
29 lines (27 loc) · 751 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
package com.github.aditya;
public class _0080 {
// Oms, faster than 100%, In place solution
class Solution {
public int removeDuplicates(int[] nums) {
if (nums.length < 3)
return nums.length;
int i = 1, j = 1;
int count = 1;
while (j < nums.length) {
if (nums[j] == nums[j - 1]) {
if (count < 2) {
nums[i] = nums[j];
i++;
}
count++;
} else {
count = 1;
nums[i] = nums[j];
i++;
}
j++;
}
return i;
}
}
}