What does " Each operand may be an integer or another expression." means?


  • 3
    F

    i have got "accepted",but i was wondering whether i got the meaning of this problem.the question said the operand can be a another expression,but if i do this,i got wrong anwser.is there a fault in the question?


  • 0
    A

    I think Each operand may be an integer or another expression means that in the original expression such as (2 + 1) * 3, operand may be an integer or another expression. but test data are Reverse Polish Notation, each token is an integer or a operator.

    Maybe, to express this problem in a less confusing way will make our world better :)


  • 0
    W

    Does this mean the intermediate results should be stored as integer? For example, should (1 / 3) * 3 be zero? I found that using a double stack failed to pass the test, but using a int stack worked.

    e.g. 10 * 6 / ((9+3) * (-11)) + 17 + 5

    Input: ["10","6", "* ", "9","3","+","-11","* ","/", "17","+","5","+"]

    Output: 21

    Expected: 22


  • 0
    Y

    Error in your input, it could be "10","6","* ","9","3","+","-11","* ","/","17","+","5","+".
    I got 22 using one int stack. So i guess intermediate results are as integers here.


  • 0
    Y

    yes, i agree. The test data seem to contain only integers and operators in each string input. If it could be an independent expression in a single string, there should be additional formatting instructions, such as "9 3 +" with space separator, etc.


  • 0
    W

    Thanks. Sorry for the typo-:)


  • 0
    W

    Seems that I must add a space after "* " to make it displayed correctly.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.