Skip to content

Commit 207c530

Browse files
authored
Added 026_Remove_Duplicates_from_Sorted_Array.java (qiyuangong#70)
* Added 026_Remove_Duplicates_from_Sorted_Array.java Contributed by @green-study
1 parent 67a8422 commit 207c530

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//026. Remove Duplicates from Sorted Array
2+
class Solution {
3+
public int removeDuplicates(int[] nums) {
4+
int index = 1;
5+
6+
for (int i = 0; i < nums.length - 1; i++) {
7+
if (nums[i] != nums[i + 1]) {
8+
nums[index] = nums[i + 1];
9+
index++;
10+
}
11+
}
12+
13+
return index;
14+
}
15+
}
16+

0 commit comments

Comments
 (0)