r/csinterviewproblems • u/pxdra • Dec 18 '15
Evaluate Math Expression
As mentioned in title.
You're given a math expression in a string, return the result as an int.
Example: "10+2*3-5/2" -> 14.
Basic: four basic operations, +-*/ Bonus: parenthesis, power.
7
Upvotes
View all comments
Show parent comment
1
u/pxdra Dec 20 '15
For the basic case (4 basic operations), you can actually tokenize the string recursively to solve it on the run. Or you can use a stack.
I found people normally either have a hard time to simply parse the string, or don't know how to handle orders of operations.