- It converts all uppercase characters to lowercase and vice versa.
def makeGood(s):
stack=[]
for i in s:
if stack and stack[-1]!=i and stack[-1].lower()==i.lower():
stack.pop()
else:
stack.append(i)
return ''.join(stack)
s='leEeetcode'
makeGood(s)
>>>
'leetcode'
### IS SAME AS BELOW
def makeGood(s):
stack=[]
for i in s:
if stack and stack[-1]==i.swapcase():
stack.pop()
else:
stack.append(i)
return ''.join(stack)
s='leEeetcode'
makeGood(s)
'Basic Python' 카테고리의 다른 글
tqdm (0) | 2022.04.07 |
---|---|
union, intersection (0) | 2022.03.10 |
@ (0) | 2021.11.15 |
itertools.islice, chain, isinstance (0) | 2021.05.25 |
pip, pip search, pip list, pip freeze, pip install, pip show (0) | 2021.05.25 |