Skip to content

Commit cfebcf4

Browse files
committed
Fix
1 parent 012d561 commit cfebcf4

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.thealgorithms.stacks;
22

3+
import java.util.Set;
34
import java.util.Stack;
45

56
/**
@@ -14,6 +15,8 @@ public final class PostfixEvaluator {
1415
private PostfixEvaluator() {
1516
}
1617

18+
private static final Set<String> OPERATORS = Set.of("+", "-", "*", "/");
19+
1720
/**
1821
* Evaluates the given postfix expression and returns the result.
1922
*
@@ -30,7 +33,7 @@ public static int evaluatePostfix(String expression) {
3033
int operand1 = stack.pop();
3134
stack.push(applyOperator(token, operand1, operand2));
3235
} else {
33-
stack.push(Integer.parseInt(token));
36+
stack.push(Integer.valueOf(token));
3437
}
3538
}
3639

@@ -48,7 +51,7 @@ public static int evaluatePostfix(String expression) {
4851
* @return true if the token is an operator, false otherwise.
4952
*/
5053
private static boolean isOperator(String token) {
51-
return token.equals("+") || token.equals("-") || token.equals("*") || token.equals("/");
54+
return OPERATORS.contains(token);
5255
}
5356

5457
/**

0 commit comments

Comments
 (0)