Skip to content

Commit

Permalink
Time: 48 ms (83.74%) | Memory: 16.6 MB (94.31%) - LeetSync
Browse files Browse the repository at this point in the history
  • Loading branch information
ShatilKhan committed Mar 4, 2024
1 parent 192da42 commit b3b2e70
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 985-bag-of-tokens/bag-of-tokens.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution:
def bagOfTokensScore(self, tokens: List[int], power: int) -> int:
res = score = 0
tokens.sort()

l, r = 0, len(tokens) - 1
while l <= r:
if power >= tokens[l]:
power -= tokens[l]
score += 1
l += 1
res = max(res, score)
elif score > 0:
power += tokens[r]
r -= 1
score -= 1
else:
break
return res

0 comments on commit b3b2e70

Please sign in to comment.