https://leetcode.com/problems/make-the-string-great/
진짜 1차원적인 기초 스택 문제
class Solution:
def makeGood(self, s: str) -> str:
stack = []
for c in s:
if not stack:
stack.append(c)
elif stack[-1] != c and stack[-1].lower() == c.lower():
stack.pop()
else:
stack.append(c)
return "".join(stack)
class Solution:
def makeGood(self, s: str) -> str:
ans = []
print(ord('A'))
print(ord('a'))
for c in s:
if ans and abs(ord(ans[-1])-ord(c)) == 32:
ans.pop()
else:
ans.append(c)
return ''.join(ans)
'algorithm' 카테고리의 다른 글
921. Minimum Add to Make Parentheses Valid (0) | 2020.10.20 |
---|---|
496. Next Greater Element I (0) | 2020.10.20 |
735. Asteroid Collision (0) | 2020.10.18 |
316. Remove Duplicate Letters [R] (0) | 2020.10.18 |
1405. Longest Happy String (0) | 2020.09.14 |