Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 57a6491

Browse files
Merge pull request TheAlgorithms#723 from pomkarnath98/master
Added test cases for LongestValidParentheses
2 parents c2b3931 + db3caea commit 57a6491

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

‎Dynamic-Programming/LongestValidParentheses.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
find the length of the longest valid (well-formed) parentheses substring.
66
*/
77

8-
const longestValidParentheses = (s) => {
8+
exportconst 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()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /