File tree 2 files changed +20
-9
lines changed 2 files changed +20
-9
lines changed Original file line number Diff line number Diff line change 5
5
find the length of the longest valid (well-formed) parentheses substring.
6
6
*/
7
7
8
- const longestValidParentheses = ( s ) => {
8
+ export const longestValidParentheses = ( s ) => {
9
9
const n = s . length
10
10
const stack = [ ]
11
11
@@ -33,11 +33,3 @@ const longestValidParentheses = (s) => {
33
33
res . push ( 0 )
34
34
return Math . max ( ...res )
35
35
}
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