Skip to content

Commit 10c594a

Browse files
committed
Added more tests for task 32.
1 parent b57ed46 commit 10c594a

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/main/java/g0001_0100/s0032_longest_valid_parentheses/Solution.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff 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
}

src/test/java/g0001_0100/s0032_longest_valid_parentheses/SolutionTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)