File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed
032_longest_valid_parentheses Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change 22#include <stdlib.h>
33
44
5+ static inline int max (int a , int b )
6+ {
7+ return a > b ? a : b ;
8+ }
9+
510static int longestValidParentheses (char * s )
611{
712 int i , cap = 18000 , invalid = -1 ;
@@ -16,17 +21,14 @@ static int longestValidParentheses(char* s)
1621 } else {
1722 if (top > stack ) {
1823 if (-- top == stack ) {
19- /* distancd of the latest ')' */
20- len = i - invalid ;
24+ /* locate the remote ')' */
25+ max_len = max ( i - invalid , max_len ) ;
2126 } else {
22- /* distance of the remote '(' */
23- len = i - * (top - 1 );
24- }
25- if (len > max_len ) {
26- max_len = len ;
27+ /* locate the remote '(' */
28+ max_len = max (i - * (top - 1 ), max_len );
2729 }
2830 } else {
29- /* record the index of last ')' but no push */
31+ /* record the index of the remote ')' and no push */
3032 invalid = i ;
3133 }
3234 }
You can’t perform that action at this time.
0 commit comments