Skip to content

Commit fffb002

Browse files
committed
optimisation de code
1 parent bd6c829 commit fffb002

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/parentheseExo/Principale.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ public static boolean estParenthese(String phrase) {
1919
stack.push("]");
2020
}
2121

22-
else if (phrase.charAt(i) == ')' && stack.peek().equals(")")) {
22+
else if (phrase.charAt(i) == ')') {
23+
if (!stack.peek().equals(")")) {
24+
return false;
25+
}
2326
stack.pop();
24-
} else if (phrase.charAt(i) == ']' && stack.peek().equals("]")) {
27+
} else if (phrase.charAt(i) == ']' ) {
28+
if (!stack.peek().equals("]")) {
29+
return false;
30+
}
2531
stack.pop();
2632
}
2733

0 commit comments

Comments
 (0)