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 961f44b commit a84bbcc
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions remove_duplicates_sorted_array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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]:
a[j] = a[i]
j += 1
a[j] = a[n - 1]
j += 1
return j


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 a84bbcc

Please sign in to comment.