일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- English
- 사이드
- 파비최
- Problem Solving
- Writing
- 괜찮음
- 미드시청
- 만화도
- 3줄정리
- 월간
- 매일
- 프로젝트
- 개발자
- 영어원서읽기
- leetcode
- 10분
- realclass
- 뭐든
- 영어공부
- FIT XR
- 쓰릴오브파이트
- 화상영어
- 잡생각
- 리얼 클래스
- Daily Challenge
- 스탭퍼
- 링피트
- 30분
- 운동
- 읽기
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.04.10 Today's Challenge 본문
https://leetcode.com/problems/valid-parentheses/
Valid Parentheses - LeetCode
Can you solve this real interview question? Valid Parentheses - Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: 1. Open brackets must be closed by the sam
leetcode.com
전형적인 스택을 활용하면 되는 문제
class Solution:
def isValid(self, s: str) -> bool:
st = []
for c in s:
if c == '(' or c == '{' or c == '[':
st.append(c)
else:
if not st:
return False
if c == ')' and st[-1] == '(':
st.pop()
elif c == '}' and st[-1] == '{':
st.pop()
elif c == ']' and st[-1] == '[':
st.pop()
else:
return False
return not st
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.04.12 Today's Challenge (0) | 2023.04.12 |
---|---|
2023.04.11 Today's Challenge (0) | 2023.04.11 |
2023.04.09 Today's Challenge (0) | 2023.04.09 |
2023.04.08 Today's Challenge (0) | 2023.04.08 |
2023.04.07 Today's Challenge (0) | 2023.04.07 |
Comments