736. Parse Lisp Expression

Description

Here

Intuition

这题目就是basic calculator的变种

  • 这个题目是有scope的,就是variable是隔离的
    • (let x 2 (mult x (let x 3 y 4 (add x y))))(let x 2 (mult (let x 3 y 4 (add x y)) x)) 是一样的,都是14
  • 这个题目的expression判别不用括号
    • 先看是不是数字,返回数字
    • 看看是不是括号开头,
      • 不是的话,说明是variable,直接从map里面捞值
      • 是的话,分3钟情况讨论

Pitfall

Solution

results matching ""

    No results matching ""