728x90
https://leetcode.com/problems/valid-parenthesis-string
class Solution:
def checkValidString(self, s: str) -> bool:
stack = []
star = []
for i, c in enumerate(s):
if c == '(':
stack.append(i)
elif c == '*':
star.append(i)
elif c == ')':
if stack:
stack.pop()
elif star:
star.pop()
else:
return False
while stack and star:
if stack[-1] > star[-1]:
return False
stack.pop()
star.pop()
if stack:
return False
return True
728x90
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 2073. Time Needed to Buy Tickets (0) | 2024.04.09 |
---|---|
[Leetcode] 1700. Number of Students Unable to Eat Lunch (0) | 2024.04.08 |
[Leetcode] 1544. Make The String Great (0) | 2024.04.05 |
[Leetcode] 938. Range Sum of BST (0) | 2024.04.05 |
[Leetcode] 205. Isomorphic Strings (0) | 2024.04.02 |