Hints — p96 Basic Calculator II

  1. Single-pass scan. Build cur_num digit by digit; defer applying the previous operator until you see the next non-digit char (or end).

  2. Deferred-operator stack: track prev_op (initially +). When finalizing cur_num: if prev_op is +/-, push signed; if *//, reduce against stack top in place.

  3. Final answer = sum(stack) because * and / already collapsed; only additively-combinable terms remain.

  4. Truncation gotcha: Python’s // rounds toward -inf. LC needs truncation toward zero. Use int(a / b).

  5. With parens (LC 224 / 772): on (, push current (result, sign); on ), pop and combine. Or write a recursive-descent parser.

If stuck: see solution.py.