일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 스탭퍼
- FIT XR
- 파비최
- realclass
- Daily Challenge
- 영어원서읽기
- 개발자
- 화상영어
- 사이드
- 리얼 클래스
- Writing
- 10분
- 쓰릴오브파이트
- 미드시청
- Problem Solving
- 만화도
- 링피트
- 매일
- English
- 뭐든
- 월간
- leetcode
- 영어공부
- 읽기
- 괜찮음
- 잡생각
- 3줄정리
- 운동
- 30분
- 프로젝트
Archives
- Today
- Total
파비의 매일매일 공부기록
Today's Challenge 본문
https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string/
Remove All Adjacent Duplicates In String - 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
n이 10^5로 좀 큰 편이라 TL 날 줄 알면서도 쉬운 방법으로 풀어봤는데 역시나 TL ㅠㅠ
# TL 난 소스
class Solution:
def removeDuplicates(self, s: str) -> str:
removed = True
while removed:
removed = False
for i in range(len(s)-1):
if s[i] == s[i+1]:
s = s[:i] + s[i+2:]
removed = True
break
return s
언제나처럼 솔루션을 봄.
OMG.... 스택을 활용하면 너무나 쉽게 풀리네 -_-;
솔루션을 보고 나니 진짜 간단한 문제였다는걸 알게됨 ㅠㅠㅠㅠ
class Solution:
def removeDuplicates(self, s: str) -> str:
st = []
for c in s:
if st and c == st[-1]:
st.pop()
continue
st.append(c)
return ''.join(st)
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
Today's Challenge (0) | 2022.11.12 |
---|---|
Today's Challenge (0) | 2022.11.11 |
Today's Challenge (0) | 2022.11.09 |
Today's Challenge (0) | 2022.11.08 |
Today's Challenge (0) | 2022.11.07 |
Comments