Python easy to understand code, beats 99.77%


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

Log in to reply
 

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