We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 48300f3 commit 6fa6be1Copy full SHA for 6fa6be1
scripts/algorithms/M/Minimum Consecutive Cards to Pick Up/Minimum Consecutive Cards to Pick Up.cpp
@@ -1,14 +1,15 @@
1
+// Runtime: 678 ms (Top 33.18%) | Memory: 115.3 MB (Top 49.54%)
2
class Solution {
3
public:
4
int minimumCardPickup(vector<int>& cards) {
-
5
+
6
int res (INT_MAX), n(size(cards));
7
unordered_map<int, int> m;
8
for (auto i=0; i<n; i++) {
9
// number of consecutive cards you have to pick up to have a pair of matching cards == (Diference between 2 indexes of same card) + 1
- 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);
11
m[cards[i]] = i;
12
}
13
return (res == INT_MAX) ? -1 : res;
14
-};
15
+};
0 commit comments