algorithm
1544. Make The String Great
식피두
2020. 10. 18. 22:05
https://leetcode.com/problems/make-the-string-great/
Make The String Great - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
진짜 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)