Skip to content

Commit 6c12467

Browse files
authored
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)