We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8f0d7e8 commit 3fca04fCopy full SHA for 3fca04f
remove-duplicates-sorted.java
@@ -0,0 +1,17 @@
1
+class Solution {
2
+ public int removeDuplicates(int[] nums) {
3
+ Set<Integer> map = new HashSet<Integer>();
4
+ int shift = 0;
5
+ for (int i = 0; i < nums.length; i++) {
6
+ if (map.contains(nums[i + shift])) {
7
+ for (int j = (i + shift); j < nums.length - 1; j++) {
8
+ nums[j] = nums[j+1];
9
+ }
10
+ shift--;
11
+ } else {
12
+ map.add(nums[i + shift]);
13
14
15
+ return nums.length + shift;
16
17
+}
0 commit comments