From c2eac7fb0aa670b69a88b4116acee4277a6ede1e Mon Sep 17 00:00:00 2001 From: unknown <1326cy@gmail.com> Date: Thu, 20 Aug 2026 22:41:09 +0900 Subject: [PATCH] day22 --- ...arrange String to Avoid Character Pair.py" | 8 ++++++ .../948. Bag of Tokens.py" | 25 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 "leetcode3/\353\202\250\355\232\250\354\240\225/3992. Rearrange String to Avoid Character Pair.py" create mode 100644 "leetcode3/\353\202\250\355\232\250\354\240\225/948. Bag of Tokens.py" diff --git "a/leetcode3/\353\202\250\355\232\250\354\240\225/3992. Rearrange String to Avoid Character Pair.py" "b/leetcode3/\353\202\250\355\232\250\354\240\225/3992. Rearrange String to Avoid Character Pair.py" new file mode 100644 index 00000000..5825391b --- /dev/null +++ "b/leetcode3/\353\202\250\355\232\250\354\240\225/3992. Rearrange String to Avoid Character Pair.py" @@ -0,0 +1,8 @@ +class Solution: + def rearrangeString(self, s: str, x: str, y: str) -> str: + x_cnt = s.count(x) + y_cnt = s.count(y) + + other_list = [char for char in s if char not in (x, y)] + + return y*y_cnt + ''.join(other_list) + x*x_cnt \ No newline at end of file diff --git "a/leetcode3/\353\202\250\355\232\250\354\240\225/948. Bag of Tokens.py" "b/leetcode3/\353\202\250\355\232\250\354\240\225/948. Bag of Tokens.py" new file mode 100644 index 00000000..2648ea3f --- /dev/null +++ "b/leetcode3/\353\202\250\355\232\250\354\240\225/948. Bag of Tokens.py" @@ -0,0 +1,25 @@ +class Solution: + def bagOfTokensScore(self, tokens: List[int], power: int) -> int: + tokens.sort() + + l = 0 + r = len(tokens) - 1 + + score = 0 + max_score = 0 + + while l <= r: + if power >= tokens[l]: + print('l', l) + score += 1 + power -= tokens[l] + l += 1 + max_score = max(max_score, score) + elif score >= 1 and l < r: + print('r', r) + score -= 1 + power += tokens[r] + r -= 1 + else: + break + return max_score \ No newline at end of file