Attempt a calculator solution
#### Is your solution the most efficient way to solve a problem? Why?
In terms of time/space asymptotic complexity, I believe so, because you can't do better than linear complexity (imagine an adversarial input `1/(1/(1/(1/( ... ))))` which does not lend itself to being simplified - you have to lex at least 3/4 of the characters in the string).
However the details of my solution are definitely not optimal - for example I could probably get away with allocating fewer slices. However I hope this has allowed me to make the solution slightly more readable. The intent behind this solution is also for me to learn a little bit about parsing.
#### Have you used any specific algorithm?
I've hand-rolled the lexer. For dealing with brackets/levels of nesting I have once again rolled my own algorithm. For parsing an expression without brackets, I have used the [shunting yard algorithm](https://en.wikipedia.org/wiki/Shunting_yard_algorithm) and then the obvious approach for evaluating an expression in reverse polish notation.
#### What is time and space complexity of your solution?
Linear time and space complexity. This is because I use a stack-based approach.
合并状态:已合并 合并于 2024-09-07 关闭于 2024-09-07 2 条评论