File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed
main/java/g0001_0100/s0032_longest_valid_parentheses
test/java/g0001_0100/s0032_longest_valid_parentheses Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ public int longestValidParentheses(String symbols) {
55 int max = 0 ;
66 char [] s = symbols .toCharArray ();
77 int [] dp = new int [s .length ];
8-
98 for (int i = 1 ; i < s .length ; i ++) {
109 if (s [i ] == ')' ) {
1110 if (s [i - 1 ] == '(' ) {
@@ -18,11 +17,9 @@ public int longestValidParentheses(String symbols) {
1817 dp [i ] += ((i - dp [i - 1 ]) >= 2 ) ? dp [i - dp [i - 1 ] - 2 ] : 0 ;
1918 }
2019 }
21-
2220 max = Math .max (max , dp [i ]);
2321 }
2422 }
25-
2623 return max ;
2724 }
2825}
Original file line number Diff line number Diff line change @@ -10,4 +10,14 @@ public class SolutionTest {
1010 public void longestValidParentheses () {
1111 assertThat (new Solution ().longestValidParentheses ("(()" ), equalTo (2 ));
1212 }
13+
14+ @ Test
15+ public void longestValidParentheses2 () {
16+ assertThat (new Solution ().longestValidParentheses (")()())" ), equalTo (4 ));
17+ }
18+
19+ @ Test
20+ public void longestValidParentheses3 () {
21+ assertThat (new Solution ().longestValidParentheses ("" ), equalTo (0 ));
22+ }
1323}
You can’t perform that action at this time.
0 commit comments