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.
1 parent aa4b61f commit 03f3aabCopy full SHA for 03f3aab
solution/0032.Longest Valid Parentheses/Solution2.java
@@ -0,0 +1,32 @@
1
+class Solution {
2
+ public int longestValidParentheses(String s) {
3
+ int res = 0;
4
+ for (int i = 0, left = 0, right = 0; i < s.length(); ++i) {
5
+ if (s.charAt(i) == '(') {
6
+ ++left;
7
+ } else {
8
+ ++right;
9
+ }
10
+ if (left == right) {
11
+ res = Math.max(res, left << 1);
12
+ } else if (left < right) {
13
+ left = 0;
14
+ right = 0;
15
16
17
+ for (int i = s.length() - 1, left = 0, right = 0; i >= 0; --i) {
18
19
20
21
22
23
24
25
+ } else if (left > right) {
26
27
28
29
30
+ return res;
31
32
+}
0 commit comments