Skip to content

Commit 08223f9

Browse files
authored
Create removeDuplicatesJava
1 parent 4d0bb8a commit 08223f9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

removeDuplicatesJava

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

0 commit comments

Comments
 (0)