Skip to content

Commit 6a55872

Browse files
authored
Create find-lucky-integer-in-an-array.py
1 parent bea76fa commit 6a55872

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Time: O(n)
2+
# Space: O(n)
3+
4+
import collections
5+
6+
7+
class Solution(object):
8+
def findLucky(self, arr):
9+
"""
10+
:type arr: List[int]
11+
:rtype: int
12+
"""
13+
count = collections.Counter(arr)
14+
result = -1
15+
for k, v in count.iteritems():
16+
if k == v:
17+
result = max(result, k)
18+
return result

0 commit comments

Comments
 (0)