Skip to content

Commit 0d4d31e

Browse files
committed
Adding Efficient Solution for Problem - 442 - Find Duplicates Array
1 parent 260d6e6 commit 0d4d31e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
##==================================
2+
## Leetcode
3+
## Student: Vandit Jyotindra Gajjar
4+
## Year: 2020
5+
## Problem: 442
6+
## Problem Name: Find All Duplicates in an Array
7+
##===================================
8+
#
9+
#Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.
10+
#
11+
#Find all the elements that appear twice in this array.
12+
#
13+
#Could you do it without extra space and in O(n) runtime?
14+
#
15+
#Example:
16+
#Input:
17+
#[4,3,2,7,8,2,3,1]
18+
#
19+
#Output:
20+
#[2,3]
21+
import collections #Importing collections module
22+
class Solution:
23+
def findDuplicates(self, nums):
24+
return ([item for item, count in collections.Counter(nums).items() if count > 1]) #Returning elements list appearing more than one time.

0 commit comments

Comments
 (0)