Skip to content

Commit 6fa6be1

Browse files
committed
Runtime: 678 ms (Top 33.18%) | Memory: 115.3 MB (Top 49.54%)
1 parent 48300f3 commit 6fa6be1

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
// Runtime: 678 ms (Top 33.18%) | Memory: 115.3 MB (Top 49.54%)
12
class Solution {
23
public:
34
int minimumCardPickup(vector<int>& cards) {
4-
5+
56
int res (INT_MAX), n(size(cards));
67
unordered_map<int, int> m;
78
for (auto i=0; i<n; i++) {
89
// number of consecutive cards you have to pick up to have a pair of matching cards == (Diference between 2 indexes of same card) + 1
9-
if (m.count(cards[i])) res = min(res, i-m[cards[i]]+1);
10+
if (m.count(cards[i])) res = min(res, i-m[cards[i]]+1);
1011
m[cards[i]] = i;
1112
}
1213
return (res == INT_MAX) ? -1 : res;
1314
}
14-
};
15+
};

0 commit comments

Comments
 (0)