Any one implemented with linkedList?

  • 1

    the problem is that how to get a Node's previous's previous of a LinkedList...

  • 0

    You can do things reversely: when you encounter a number, add it to the HEAD of the linked list; when encountering an operator, perform its corresponding operation on HEAD and HEAD.NEXT, remove both nodes, then add the their result back to the HEAD. Since we only need access to the first (sometimes second) element in the element, we might as well use a stack in the first place.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.