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,24 @@

'''
1. 아이디어 :
그냥 y를 먼저 붙이고, 나머지 문자를 붙인다.
x 몰라도 그냥 풀림

2. 시간복잡도 :
o(n)

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

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

for i in s:
if i == y:
tmp += i
else:
ans += i

return tmp+ans
41 changes: 41 additions & 0 deletions leetcode3/변지협/v2/948. Bag of Tokens.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

'''
1. 아이디어 :
점수를 잃을땐 최대 power를 얻고, 점수를 얻을 땐 최소 pwoer를 소모한다.

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

3. 자료구조/알고리즘 :
투포인터
'''


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

a = 0
b = n - 1
score = 0
ans = 0

while True:
print('a,b,power,score:', a,b,power)
if a > b:
break

if power >= tokens[a]:
power -= tokens[a]
score +=1
ans = max([score, ans])
a += 1
else:
if score == 0:
break
power += tokens[b]
score -= 1
b -= 1

return ans