Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ed8ca44

Browse files
authored
Create Minimum Consecutive Cards to Pick Up.java
1 parent 17dde8d commit ed8ca44

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public int minimumCardPickup(int[] cards) {
3+
int minCount = Integer.MAX_VALUE;
4+
Map<Integer, Integer> map = new HashMap<>();
5+
for (int i = 0; i < cards.length; i++) {
6+
if (map.containsKey(cards[i])) {
7+
minCount = Math.min(minCount, i - map.get(cards[i]) + 1);
8+
}
9+
map.put(cards[i], i);
10+
}
11+
return minCount == Integer.MAX_VALUE ? -1 : minCount;
12+
}
13+
}

0 commit comments

Comments
 (0)