File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55 find the length of the longest valid (well-formed) parentheses substring.
66*/
77
8- const longestValidParentheses = ( s ) => {
8+ export const longestValidParentheses = ( s ) => {
99 const n = s . length
1010 const stack = [ ]
1111
@@ -33,11 +33,3 @@ const longestValidParentheses = (s) => {
3333 res . push ( 0 )
3434 return Math . max ( ...res )
3535}
36-
37- const main = ( ) => {
38- console . log ( longestValidParentheses ( ')()())' ) ) // output -> 4
39- console . log ( longestValidParentheses ( '' ) ) // output -> 0
40- console . log ( longestValidParentheses ( '(()' ) ) // output -> 2
41- }
42-
43- main ( )
Original file line number Diff line number Diff line change 1+ import { longestValidParentheses } from '../LongestValidParentheses'
2+
3+ describe ( 'longestValidParentheses' , ( ) => {
4+ it ( 'expects to return 0 as longest valid parentheses substring' , ( ) => {
5+ expect ( longestValidParentheses ( '' ) ) . toBe ( 0 )
6+ } )
7+
8+ it ( 'expects to return 2 as longest valid parentheses substring' , ( ) => {
9+ expect ( longestValidParentheses ( '(()' ) ) . toBe ( 2 )
10+ } )
11+
12+ it ( 'expects to return 2 as longest valid parentheses substring' , ( ) => {
13+ expect ( longestValidParentheses ( ')()())' ) ) . toBe ( 4 )
14+ } )
15+
16+ it ( 'expects to return 2 as longest valid parentheses substring' , ( ) => {
17+ expect ( longestValidParentheses ( '(((' ) ) . toBe ( 0 )
18+ } )
19+ } )
You can’t perform that action at this time.
0 commit comments