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

Commit8077f35

Browse files
Update 0948-bag-of-tokens.java
1 parent72b8d84 commit8077f35

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

‎java/0948-bag-of-tokens.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,27 @@ public int bagOfTokensScore(int[] tokens, int power) {
2222
returnres;
2323
}
2424
}
25+
26+
/*------------------------------------------------------*/
27+
28+
classSolution {
29+
publicintbagOfTokensScore(int[]tokens,intpower) {
30+
Arrays.sort(tokens);
31+
intscore =0;
32+
inti =0,j =tokens.length -1;
33+
while (i <j) {
34+
if (power >=tokens[i]) {
35+
power -=tokens[i++];
36+
score +=1;
37+
}
38+
elseif (score >0 &&i !=j) {
39+
score -=1;
40+
power +=tokens[j--];
41+
}
42+
else
43+
break;
44+
}
45+
returnscore;
46+
}
47+
}
48+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp