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 2
2
#include <stdlib.h>
3
3
4
4
5
+ static inline int max (int a , int b )
6
+ {
7
+ return a > b ? a : b ;
8
+ }
9
+
5
10
static int longestValidParentheses (char * s )
6
11
{
7
12
int i , cap = 18000 , invalid = -1 ;
@@ -16,17 +21,14 @@ static int longestValidParentheses(char* s)
16
21
} else {
17
22
if (top > stack ) {
18
23
if (-- top == stack ) {
19
- /* distancd of the latest ')' */
20
- len = i - invalid ;
24
+ /* locate the remote ')' */
25
+ max_len = max ( i - invalid , max_len ) ;
21
26
} 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 );
27
29
}
28
30
} else {
29
- /* record the index of last ')' but no push */
31
+ /* record the index of the remote ')' and no push */
30
32
invalid = i ;
31
33
}
32
34
}
You can’t perform that action at this time.
0 commit comments