Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6c12467

Browse files
Update Longest Valid Parentheses
1 parent 6d07c92 commit 6c12467

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

‎精選高頻HARD題目/Longest Valid Parentheses

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
想法:用一個 stack 紀錄左括號的位置,當出現右括號時一定是與最右邊的左括號抵銷,也就是 stack 的頂部元素
2-
所以抵銷後的合法 substring 必然是從第二個元素到目前位置為子字串長度
2+
所以抵銷後的合法 substring 必然是從第二個元素的後一個位置到目前位置為子字串長度
33
只需注意如果 stack 抵銷後已經空了的話,代表從 s[startvalidindex ... i] 都是合法子字串
44
startvalidindex 會因為 右括號多於左括號(代表不可能出現合法字串)而向後更動
55

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /