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

Commit 68c8fd4

Browse files
added daily challenge
1 parent 81c0cc8 commit 68c8fd4

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎948. Bag of Tokens.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution(object):
2+
def bagOfTokensScore(self, tokens, power):
3+
tokens.sort()
4+
n = len(tokens)
5+
score = 0
6+
max_score = 0
7+
left = 0
8+
right = n - 1
9+
10+
while left <= right:
11+
if power >= tokens[left]:
12+
power -= tokens[left]
13+
score += 1
14+
left += 1
15+
max_score = max(max_score, score)
16+
elif score > 0:
17+
power += tokens[right]
18+
score -= 1
19+
right -= 1
20+
else:
21+
break
22+
23+
return max_score

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /