Skip to content

Commit ca8f41b

Browse files
Merge pull request #1877 from CodingTestStudy2/남효정
[남효정] Day22
2 parents d48d319 + c2eac7f commit ca8f41b

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution:
2+
def rearrangeString(self, s: str, x: str, y: str) -> str:
3+
x_cnt = s.count(x)
4+
y_cnt = s.count(y)
5+
6+
other_list = [char for char in s if char not in (x, y)]
7+
8+
return y*y_cnt + ''.join(other_list) + x*x_cnt
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution:
2+
def bagOfTokensScore(self, tokens: List[int], power: int) -> int:
3+
tokens.sort()
4+
5+
l = 0
6+
r = len(tokens) - 1
7+
8+
score = 0
9+
max_score = 0
10+
11+
while l <= r:
12+
if power >= tokens[l]:
13+
print('l', l)
14+
score += 1
15+
power -= tokens[l]
16+
l += 1
17+
max_score = max(max_score, score)
18+
elif score >= 1 and l < r:
19+
print('r', r)
20+
score -= 1
21+
power += tokens[r]
22+
r -= 1
23+
else:
24+
break
25+
return max_score

0 commit comments

Comments
 (0)