File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change
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.
You can’t perform that action at this time.
0 commit comments