LeetCode 227 Basic Calculator II - Why Naive Fails

The trap

Process operators left to right in order.

This ignores operator precedence. 3+2*2 would incorrectly compute (3+2)*2 = 10 instead of 3+(2*2) = 7.

You need to handle * and / immediately while deferring + and - for later.