-
99클럽 코테 스터디 15일차 TIL: 스택/큐, Leetcode 2390. Removing Stars From a StringToday_I_Learned/Algorithm 2024. 6. 24. 22:48
문제
https://leetcode.com/problems/removing-stars-from-a-string/description/
통과 여부
Pass
나의 접근
- 문자열을 순회하며 문자를 하나씩 string 변수에 붙인다.
- * 을 만나면 string 변수의 마지막 문자를 제거한다.
시간 복잡도 측면에서 더 좋은 방법 (항해99 스터디를 통해 알게 된 방법)
- stack 에 넣고, * 이 나오면 stack 을 pop 한다.
class Solution: def removeStars(self, s: str) -> str: ans = '' for c in s: if c != '*': ans += c else: ans = ans[:-1] return ans
'Today_I_Learned > Algorithm' 카테고리의 다른 글