diff --git "a/leetcode3/\353\263\200\354\247\200\355\230\221/v2/3992. Rearrange String to Avoid Character Pair.py" "b/leetcode3/\353\263\200\354\247\200\355\230\221/v2/3992. Rearrange String to Avoid Character Pair.py" new file mode 100644 index 00000000..e310a3b2 --- /dev/null +++ "b/leetcode3/\353\263\200\354\247\200\355\230\221/v2/3992. Rearrange String to Avoid Character Pair.py" @@ -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 \ No newline at end of file diff --git "a/leetcode3/\353\263\200\354\247\200\355\230\221/v2/948. Bag of Tokens.py" "b/leetcode3/\353\263\200\354\247\200\355\230\221/v2/948. Bag of Tokens.py" new file mode 100644 index 00000000..22819446 --- /dev/null +++ "b/leetcode3/\353\263\200\354\247\200\355\230\221/v2/948. Bag of Tokens.py" @@ -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 \ No newline at end of file