Easy to understand Python code, beats 96.42% Python submissions


  • 0
    class Solution(object):
        def inorderTraversal(self, root):
            if root == None: return []
            r = []; st = []; node = root
            st.append(root)
            while st:
                while node and node.left:
                    st.append(node.left)
                    node = node.left
                node = st.pop()
                r.append(node.val)
                node = node.right
                if node: st.append(node)
            return r
    

Log in to reply
 

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