Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#

'''
1. 아이디어 :


2. 시간복잡도 :
O()

3. 자료구조/알고리즘 :


'''
class Solution:
def rearrangeString(self, s: str, x: str, y: str) -> str:
counter = Counter(s)

ans = ""
if y in counter:
ans += y*counter[y]
if x in counter:
ans += x*counter[x]
for char, freq in counter.items():
if char == x or char == y:
continue
ans += char * freq
return ans
40 changes: 40 additions & 0 deletions leetcode3/최원준/948. Bag of Tokens.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#

'''
1. 아이디어 :
더할때는 가장 큰것부터, 뺄때는 가장 작은것부터.

2. 시간복잡도 :
O(nlogn)

3. 자료구조/알고리즘 :
two pointer

'''
class Solution:
def bagOfTokensScore(self, tokens: List[int], power: int) -> int:
n = len(tokens)
tokens.sort()

left = 0
right = n-1
score = 0
ans = 0

while left<=right:
if power>=tokens[left]:
power -= tokens[left]
left+=1
score+=1
ans = max(ans, score)
elif score>0:
power += tokens[right]
right-=1
score-=1
else:
break
return ans