Evaluate Reverse Polish Notation

Evaluate the value of an arithmetic expression in Reverse Polish Notation.
Valid operators are +-*/. Each operand may be an integer or another expression.
Some examples:
  ["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9
  ["4", "13", "5", "/", "+"] -> (4 + (13 / 5)) -> 6
Bug free. Could done better if we add more error handling (instead of checking +-*/, we could have more invalid inputs)

Comments

  1. Hi,

    What will be the result when the Final thing is out of bounds ? like 3/0 = Infinity(>Integer.MAX_VALUE);

    Thanks,
    Guru

    ReplyDelete

Post a Comment

Popular posts from this blog

Maximum Gap

[ITint5] Maximum Subarray for a Circular Array

[CC150] Chapter 8 Object-Oriented Design