diff --git a/DynamicProgramming/Longest_Valid_Parenthesis.cpp b/DynamicProgramming/Longest_Valid_Parenthesis.cpp new file mode 100644 index 0000000..9866bdf --- /dev/null +++ b/DynamicProgramming/Longest_Valid_Parenthesis.cpp @@ -0,0 +1,22 @@ +// Link to the question : https://leetcode.com/problems/longest-valid-parentheses/ + +class Solution { +public: + int longestValidParentheses(string s) { + int n=s.length(), maxLength=0; + stack st; + st.push(-1); + + for(int i=0;i