Skip to content

Commit dede649

Browse files
Create remove_duplicate.py
created a program to remove duplicate values from a given sorted array
1 parent a71618f commit dede649

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Program to remove duplicates from a sorted array
2+
3+
# Input: sorted array
4+
arr = [1, 1, 2, 2, 3, 4, 4, 5]
5+
6+
print("Original array:", arr)
7+
8+
# Create an empty list to store unique elements
9+
unique_arr = []
10+
11+
# Traverse the array
12+
for num in arr:
13+
# Add the number only if it's not already in unique_arr
14+
if len(unique_arr) == 0 or num != unique_arr[-1]:
15+
unique_arr.append(num)
16+
17+
print("Array after removing duplicates:", unique_arr)

0 commit comments

Comments
 (0)