Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commited8ca44

Browse files
authored
Create Minimum Consecutive Cards to Pick Up.java
1 parent17dde8d commited8ca44

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+
classSolution {
2+
publicintminimumCardPickup(int[]cards) {
3+
intminCount =Integer.MAX_VALUE;
4+
Map<Integer,Integer>map =newHashMap<>();
5+
for (inti =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+
returnminCount ==Integer.MAX_VALUE ? -1 :minCount;
12+
}
13+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp