0
How to find repeated numbers in an array if it contains multiple duplicates?
In that case, an array contains only one duplicate but what if it contains multiple duplicates? Suppose, an array contains n numbers ranging from 0 to n-1 and there are 5 duplicates on it, how to find ?
4 Respostas
+ 2
Which language?
https://code.sololearn.com/W3uiji9X28C1/?ref=app
+ 2
l=[1,3,4,4,5,7,7,7,8,9,78,46]
print({i for i in l if l.count(i) > 1 })
will print {4,7}
0
Use array elements as key and their frequency as value with dictionary
0
arr = [1, 2, 3, 4, 2, 7, 8, 8, 3]
print("Duplicate elements: ")
for i in range(0, len(arr)):
for j in range(+1, len(arr)):
if(arr[i] == arr[j]):
print(arr[j])