Evaluate Reverse Polish Notation: Exceptions


  • 0
    P

    Should I consider exceptions in calculation or pop from an empty stack?

    For example, if I have an error input ["3", "+"]. When doing the add operation, the second pop will throw exception, should I catch it?

    Another error input is ["5", "0", "/"], 5/0 is not valid for divide. Should I also avoid it?

    Thanks.


  • 0
    M

    No you don't need to worry about exception in this context. Well, you would need to code it to handle all thrown exceptions, but you don't need to think about what to do in such case.


Log in to reply
 

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