Skip to content

Commit 10e7464

Browse files
committed
Adding Efficient Solution for Problem - 287 - Find Duplicate Number
1 parent d5d8524 commit 10e7464

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
##==================================
2+
## Leetcode
3+
## Student: Vandit Jyotindra Gajjar
4+
## Year: 2020
5+
## Problem: 287
6+
## Problem Name: Find the Duplicate Number
7+
##===================================
8+
#
9+
#Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive),
10+
#prove that at least one duplicate number must exist. Assume that there is only one duplicate number,
11+
#find the duplicate one.
12+
#
13+
#Example 1:
14+
#
15+
#Input: [1,3,4,2,2]
16+
#Output: 2
17+
#Example 2:
18+
#
19+
#Input: [3,1,3,4,2]
20+
#Output: 3
21+
class Solution:
22+
def findDuplicate(self, nums):
23+
return "".join([str(key) for key, val in collections.Counter(nums).items() if val != 1]) #Return the duplicate number

0 commit comments

Comments
 (0)