We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents e34a83a + a87399b commit 1340e22Copy full SHA for 1340e22
leetcode/cpp/Stacks/32.cpp
@@ -0,0 +1,25 @@
1
+//Longest valid parentheses
2
+
3
+class Solution {
4
+public:
5
+ int longestValidParentheses(string s) {
6
+ stack<int> st;
7
+ int len = 0;
8
+ st.push(-1);
9
+ for(int i=0;i<s.length();i++){
10
+ if(s[i] == '('){
11
+ st.push(i);
12
+ }
13
+ else{
14
+ st.pop();
15
+ if(!st.empty()){
16
+ len=max(len,i - st.top());
17
18
19
20
21
22
23
+ return len;
24
25
+};
0 commit comments