일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 사이드
- 괜찮음
- 매일
- leetcode
- 3줄정리
- 파비최
- 프로젝트
- 읽기
- 잡생각
- English
- 개발자
- realclass
- 화상영어
- Problem Solving
- Daily Challenge
- FIT XR
- 10분
- 미드시청
- 리얼 클래스
- 영어원서읽기
- 월간
- 영어공부
- 운동
- 링피트
- 뭐든
- 30분
- Writing
- 스탭퍼
- 만화도
- 쓰릴오브파이트
Archives
- Today
- Total
파비의 매일매일 공부기록
Today's Challenge 본문
https://leetcode.com/problems/longest-valid-parentheses/
Longest Valid Parentheses - 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
스택을 이용한 LCS 구하는 문제.
class Solution:
def longestValidParentheses(self, s: str) -> int:
max_ans = 0
st = [-1]
for i in range(len(s)):
if s[i] == '(':
st.append(i)
else:
st.pop()
if len(st) == 0:
st.append(i)
else:
max_ans = max(max_ans, i-st[-1])
return max_ans
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
Today's Challenge (0) | 2022.05.26 |
---|---|
Today's Challenge (0) | 2022.05.25 |
Today's Challenge (0) | 2022.05.23 |
Today's Challenge (0) | 2022.05.22 |
Today's Challenge (0) | 2022.05.21 |
Comments