Skip to content

Commit 50e3c9d

Browse files
committed
fix: add braces to satisfy Checkstyle NeedBraces rule
1 parent 47d1ec6 commit 50e3c9d

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

src/main/java/com/thealgorithms/stacks/ValidParentheses.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
import java.util.Deque;
55
import java.util.Map;
66

7-
/**
8-
* Utility class to check if a string has valid parentheses.
9-
*/
107
public final class ValidParentheses {
118

129
private ValidParentheses() {
@@ -15,20 +12,19 @@ private ValidParentheses() {
1512

1613
private static final Map<Character, Character> PAIRS = Map.of(')', '(', '}', '{', ']', '[');
1714

18-
/**
19-
* Checks if the input string has valid parentheses.
20-
*
21-
* @param s the input string
22-
* @return true if valid, false otherwise
23-
*/
2415
public static boolean isValid(final String s) {
25-
if (s == null) throw new NullPointerException("Input cannot be null");
16+
if (s == null) {
17+
throw new NullPointerException("Input cannot be null");
18+
}
19+
2620
Deque<Character> stack = new ArrayDeque<>();
2721
for (char ch : s.toCharArray()) {
2822
if (PAIRS.containsValue(ch)) {
2923
stack.push(ch);
3024
} else if (PAIRS.containsKey(ch)) {
31-
if (stack.isEmpty() || stack.pop() != PAIRS.get(ch)) return false;
25+
if (stack.isEmpty() || stack.pop() != PAIRS.get(ch)) {
26+
return false;
27+
}
3228
}
3329
}
3430
return stack.isEmpty();

0 commit comments

Comments
 (0)