Solved LeetCode program · 32 of 1,000
#0032 · Longest Valid Parentheses
Original English source
The text is "(()". The last is the last position of text. The best is 0.
For every start from 0 to last.
The balance is 0.
For every end from start to last.
If character end of text is "(", add 1 to balance. If character end of text is ")", subtract 1 from balance. If balance is less than 0, break. If balance is 0, The width is end minus start plus 1, if width is more than best, set best to width.
Report best.
Expected stdout
2