Skip to content

Commit

Permalink
Remove Duplicates from Sorted Array
Browse files Browse the repository at this point in the history
  • Loading branch information
altruistcoder committed Aug 13, 2019
1 parent a84bbcc commit 303316b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,6 @@ This is a repository containing various python programs to understand the basic

Python Code for finding the first non-repeating character present in the given string.

* [Remove Duplicates from a Sorted Array](https://github.com/altruistcoder/Data-Structures-Python/blob/master/remove_duplicates_sorted_array.py):

Python Code for removing duplicate elements present in a sorted array.
5 changes: 3 additions & 2 deletions remove_duplicates_sorted_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ def removeDuplicates(a, n):
if n == 0 or n == 1:
return n
j = 0
for i in range(0, n - 1):
if a[i] != a[i + 1]:
for i in range(0, n-1):
if a[i] != a[i+1]:
a[j] = a[i]
j += 1
a[j] = a[n - 1]
Expand All @@ -14,5 +14,6 @@ def removeDuplicates(a, n):
a = list(map(int, input("Enter a list of elements: ").split()))
n = len(a)
m = removeDuplicates(a, n)

print("The resultant array is:")
[print(a[i], end=" ") for i in range(m)]

0 comments on commit 303316b

Please sign in to comment.