Skip to content

Commit 20a34b4

Browse files
committed
Remove Duplicates from sorted Array
1 parent 8cdb87a commit 20a34b4

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

LeetCode/Arrays/RemoveDuplicates.java

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

0 commit comments

Comments
 (0)