Skip to content

Commit 386743c

Browse files
authored
26.RemoveDuplicates-双指针
1 parent e9c3901 commit 386743c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

RemoveDuplicates.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int removeDuplicates(int[] nums) {
3+
int n = nums.length;
4+
int l = 0;
5+
int r = 1;
6+
while(r < n) {
7+
if (nums[l] != nums[r]) {
8+
l++;
9+
nums[l] = nums[r];
10+
}
11+
r++;
12+
}
13+
return l+1;
14+
}
15+
}

0 commit comments

Comments
 (0)