Skip to content

Commit 3489518

Browse files
authored
Create minimum-consecutive-cards-to-pick-up.py
1 parent 85ac94d commit 3489518

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Time: O(n)
2+
# Space: O(n)
3+
4+
# hash table
5+
class Solution(object):
6+
def minimumCardPickup(self, cards):
7+
"""
8+
:type cards: List[int]
9+
:rtype: int
10+
"""
11+
lookup = {}
12+
result = float("inf")
13+
for i, x in enumerate(cards):
14+
if x in lookup:
15+
result = min(result, i-lookup[x]+1)
16+
lookup[x] = i
17+
return result if result != float("inf") else -1

0 commit comments

Comments
 (0)