Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7b75389

Browse files
solves remove duplicate elements from sorted arrray
1 parent 8d56e09 commit 7b75389

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
| Question | Solution | Youtube |
2727
|------|:--------:|:----------------------:|
2828
| [Remove Element](https://leetcode.com/explore/learn/card/fun-with-arrays/526/deleting-items-from-an-array/3247/) | [![Java](assets/java.png)](java/src/RemoveElement.java) [![Python](assets/python.png)](python/remove_element.py) |
29-
| [Remove Duplicates from Sorted Array](https://leetcode.com/explore/learn/card/fun-with-arrays/526/deleting-items-from-an-array/3248/) | [![Java](assets/java.png)](java/src/) [![Python](assets/python.png)](python/) |
29+
| [Remove Duplicates from Sorted Array](https://leetcode.com/explore/learn/card/fun-with-arrays/526/deleting-items-from-an-array/3248/) | [![Java](assets/java.png)](java/src/RemoveDuplicatesFromSortedArray.java) [![Python](assets/python.png)](python/remove_duplicate_elements_from_sorted_array.py) |
3030

3131

3232
## Searching For Items In An Array
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class RemoveDuplicatesFromSortedArray {
2+
public int removeDuplicates(int[] array) {
3+
if(array.length == 0) return 0;
4+
int finalLength = 1;
5+
for (int index = 1, current = array[0] ; index < array.length ; index++) {
6+
if (array[index] != current) {
7+
array[finalLength] = array[index];
8+
finalLength++;
9+
current = array[index];
10+
}
11+
}
12+
return finalLength;
13+
}
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def removeDuplicates(self, nums: List[int]) -> int:
6+
if len(nums) is 0: return 0
7+
finalLength = 1
8+
index, current = 1, nums[0]
9+
while index < len(nums):
10+
if nums[index] != current:
11+
nums[finalLength] = nums[index]
12+
finalLength += 1
13+
current = nums[index]
14+
index += 1
15+
return finalLength

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /