Javascript easy stack with comments
\nvar longestValidParentheses = function(s) {\n    if(s.length === 0) return 0;\n    \n    let stack = [-1];\n    let max = 0;\n    \n    for(let i = 0; i < s.l
```\nvar longestValidParentheses = function(s) {\n    if(s.length === 0) return 0;\n    \n    let stack = [-1];\n    let max = 0;\n    \n    for(let i = 0; i < s.length; i++) {\n        //push into stack if opening paran\n        if(s[i] === \'(\') {\n            stack.push(i);\n        } else {\n            // pop out if it\'s an closing paran\n            stack.pop();\n            \n            // if we don\'t hav anything in stack, push this new index\n            if(stack.length === 0) {\n                stack.push(i);\n            } else {\n                // i - stack[stack.length - 1] is length of longest substr\n                max = Math.max(max, i - stack[stack.length - 1]);\n            }\n        }\n    }\n    return max;\n};\n```
['Stack', 'JavaScript']