mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 16:26:47 +08:00
Merge pull request #723 from pomkarnath98/master
Added test cases for LongestValidParentheses
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
find the length of the longest valid (well-formed) parentheses substring.
|
||||
*/
|
||||
|
||||
const longestValidParentheses = (s) => {
|
||||
export const longestValidParentheses = (s) => {
|
||||
const n = s.length
|
||||
const stack = []
|
||||
|
||||
@ -33,11 +33,3 @@ const longestValidParentheses = (s) => {
|
||||
res.push(0)
|
||||
return Math.max(...res)
|
||||
}
|
||||
|
||||
const main = () => {
|
||||
console.log(longestValidParentheses(')()())')) // output -> 4
|
||||
console.log(longestValidParentheses('')) // output -> 0
|
||||
console.log(longestValidParentheses('(()')) // output -> 2
|
||||
}
|
||||
|
||||
main()
|
||||
|
19
Dynamic-Programming/tests/LongestValidParentheses.test.js
Normal file
19
Dynamic-Programming/tests/LongestValidParentheses.test.js
Normal file
@ -0,0 +1,19 @@
|
||||
import { longestValidParentheses } from '../LongestValidParentheses'
|
||||
|
||||
describe('longestValidParentheses', () => {
|
||||
it('expects to return 0 as longest valid parentheses substring', () => {
|
||||
expect(longestValidParentheses('')).toBe(0)
|
||||
})
|
||||
|
||||
it('expects to return 2 as longest valid parentheses substring', () => {
|
||||
expect(longestValidParentheses('(()')).toBe(2)
|
||||
})
|
||||
|
||||
it('expects to return 2 as longest valid parentheses substring', () => {
|
||||
expect(longestValidParentheses(')()())')).toBe(4)
|
||||
})
|
||||
|
||||
it('expects to return 2 as longest valid parentheses substring', () => {
|
||||
expect(longestValidParentheses('(((')).toBe(0)
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user