请大家参谋下能不能直接pp# Immigration - 落地生根
y*3
1 楼
Evaluate Reverse Polish Notation那道题,超级容易的,我在Eclipse上都run通了,
但是leetcode却过不了一个最简单的case。实在是不明觉厉。。。
Submission Result: Runtime Error
Last executed input: ["0","3","/"]
public class Solution {
public int evalRPN(String[] tokens) {
java.util.Stack sTokens = new java.util.Stack();
for(int i = 0; i < tokens.length; i++)
{
if (tokens[i] != "+" && tokens[i] != "-" && tokens[i] != "*" &&
tokens[i] != "/")
{
int currInt = Integer.parseInt(tokens[i]);
sTokens.push(currInt);
}
else
{
int int2 = sTokens.pop();
int int1 = sTokens.pop();
int int3 = 0;
if (tokens[i] == "+")
{
int3 = int1 + int2;
}
if (tokens[i] == "-")
{
int3 = int1-int2;
}
if (tokens[i] == "*")
{
int3 = int1 * int2;
}
if (tokens[i] == "/")
{
int3 = int1/int2;
}
sTokens.push(int3);
}
}
return sTokens.pop();
}
}
但是leetcode却过不了一个最简单的case。实在是不明觉厉。。。
Submission Result: Runtime Error
Last executed input: ["0","3","/"]
public class Solution {
public int evalRPN(String[] tokens) {
java.util.Stack
for(int i = 0; i < tokens.length; i++)
{
if (tokens[i] != "+" && tokens[i] != "-" && tokens[i] != "*" &&
tokens[i] != "/")
{
int currInt = Integer.parseInt(tokens[i]);
sTokens.push(currInt);
}
else
{
int int2 = sTokens.pop();
int int1 = sTokens.pop();
int int3 = 0;
if (tokens[i] == "+")
{
int3 = int1 + int2;
}
if (tokens[i] == "-")
{
int3 = int1-int2;
}
if (tokens[i] == "*")
{
int3 = int1 * int2;
}
if (tokens[i] == "/")
{
int3 = int1/int2;
}
sTokens.push(int3);
}
}
return sTokens.pop();
}
}