Skip to content

Commit 6f50206

Browse files
committed
Fix
1 parent 2f07871 commit 6f50206

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/main/java/com/thealgorithms/stacks/PrefixEvaluator.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 PrefixEvaluator {
1415
private PrefixEvaluator() {
1516
}
1617

18+
private static final Set<String> OPERATORS = Set.of("+", "-", "*", "/");
19+
1720
/**
1821
* Evaluates the given prefix expression and returns the result.
1922
*
@@ -32,7 +35,7 @@ public static int evaluatePrefix(String expression) {
3235
int operand2 = stack.pop();
3336
stack.push(applyOperator(token, operand1, operand2));
3437
} else {
35-
stack.push(Integer.parseInt(token));
38+
stack.push(Integer.valueOf(token));
3639
}
3740
}
3841

@@ -50,7 +53,7 @@ public static int evaluatePrefix(String expression) {
5053
* @return true if the token is an operator, false otherwise.
5154
*/
5255
private static boolean isOperator(String token) {
53-
return token.equals("+") || token.equals("-") || token.equals("*") || token.equals("/");
56+
return OPERATORS.contains(token);
5457
}
5558

5659
/**

0 commit comments

Comments
 (0)