From 398219824493386e06160e1dce11648a176fd4f8 Mon Sep 17 00:00:00 2001 From: ShrutiAggarwal99 <31125152+ShrutiAggarwal99@users.noreply.github.com> Date: Mon, 14 Oct 2019 21:42:41 +0530 Subject: [PATCH] Create Longest_Valid_Parenthesis.cpp --- .../Longest_Valid_Parenthesis.cpp | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 DynamicProgramming/Longest_Valid_Parenthesis.cpp 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