From a21a06567385b416f94ddb95d612aee4d8410049 Mon Sep 17 00:00:00 2001 From: shrut_512 <84448891+Shrut012@users.noreply.github.com> Date: Mon, 31 Oct 2022 21:57:31 +0530 Subject: [PATCH] Create Longest Valid Parentheses.cpp Given a string containing just the characters '(' and ')', return the length of the longest valid (well-formed) parentheses substring. --- Longest Valid Parentheses.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Longest Valid Parentheses.cpp diff --git a/Longest Valid Parentheses.cpp b/Longest Valid Parentheses.cpp new file mode 100644 index 0000000..8a50df8 --- /dev/null +++ b/Longest Valid Parentheses.cpp @@ -0,0 +1,32 @@ +/* +Given a string containing just the characters '(' and ')', return the length of the longest valid (well-formed) parentheses substring. + + + +Example 1: + +Input: s = "(()" +Output: 2 +Explanation: The longest valid parentheses substring is "()". +*/ + +class Solution { +public: + int longestValidParentheses(string s) { + stack stk; + stk.push(-1); + int maxL=0; + for(int i=0;i