Simple python solution 40ms


  • 0
    F
    class Solution:
        def inorderTraversal(self, root):
            ret = []
            stack = []
            p = root
            while True:
                if p == None:
                    try:
                        p = stack.pop()
                    except:
                        break   # end of tree
                    ret.append(p.val)
                    p = p.right
                elif p.left:
                    stack.append(p)
                    p = p.left
                else:           # p.right
                    ret.append(p.val)
                    p = p.right
            return ret

Log in to reply
 

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