LeetCode: 32-Longest Valid Parentheses 解題紀錄
題目
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.
Example:
Input: s = "(()"
Output: 2
Explanation: The longest valid parentheses substring is "()".
Input: s = ")()())"
Output: 4
Explanation: The longest valid parentheses substring is "()()".
這個題目輸入一個只由 '(' 或是 ')' 組成的字串,而我們要做的,就是判斷最長的『合理』子字串長度。
比方說, "()" 就是合理的子字串、")(" 就是個不合理的子字串。
Read More »LeetCode: 32-Longest Valid Parentheses 解題紀錄