File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -36,3 +36,42 @@ const longestValidParentheses = function(s) {
36
36
37
37
return longest
38
38
}
39
+
40
+ // another
41
+
42
+ /**
43
+ * @param {string } s
44
+ * @return {number }
45
+ */
46
+ const longestValidParentheses = function ( s ) {
47
+ let res = 0 ,
48
+ stk = [ ] ,
49
+ n = s . length ,
50
+ idxStk = [ ]
51
+ for ( let i = 0 ; i < n ; i ++ ) {
52
+ const ch = s [ i ]
53
+ if ( stk . length && stk [ stk . length - 1 ] === '(' && ch === ')' )
54
+ stk . pop ( ) , idxStk . pop ( )
55
+ else stk . push ( ch ) , idxStk . push ( i )
56
+ res = Math . max ( res , i - ( idxStk . length ? idxStk [ idxStk . length - 1 ] : - 1 ) )
57
+ }
58
+ return res
59
+ }
60
+ /**
61
+ * @param {string } s
62
+ * @return {number }
63
+ */
64
+ const longestValidParentheses = function ( s ) {
65
+ let res = 0 ,
66
+ stk = [ ] ,
67
+ n = s . length ,
68
+ idxStk = [ ]
69
+ for ( let i = 0 ; i < n ; i ++ ) {
70
+ const ch = s [ i ]
71
+ if ( stk . length && stk [ stk . length - 1 ] === '(' && ch === ')' )
72
+ stk . pop ( ) , idxStk . pop ( )
73
+ else stk . push ( ch ) , idxStk . push ( i )
74
+ res = Math . max ( res , i - ( idxStk . length ? idxStk [ idxStk . length - 1 ] : - 1 ) )
75
+ }
76
+ return res
77
+ }
You can’t perform that action at this time.
0 commit comments