
[LeetCode] 3174. Clear Digits (Python)
·
코딩 테스트
Problem Solutionstring, stack문자열 s에서 digit이 있으면 digit 과 그 왼쪽에있는 문자를 제거하는 문제 (반복).문자열을 순회하면서 해당 index를 기준으로 digit 여부와 왼쪽 문자를 체크하여 s 를 업데이트한 후 조건에 해당되지 않을 때까지 반복한다. 다른 코드에서는 alpha이면 list에 저장하고 그 다음 문자가 digit이면 pop하여 list에서 제거한 뒤 최종적으로 string으로 concat 해서 반환한다.class Solution: def clearDigits(self, s: str) -> str: stack = [] for char in s: if char.isdigit(): ..