A simple inOrderSort python solution


  • 0
    F

    Please share your thoughts on this: Looks like the traditional inOrder Traverse works here too

    class Solution(object):

    def kthSmallest(self, root, k):
        l = []
        self.inOrderSort( root, l)
        return l[k-1]
        
    def inOrderSort(self, node,  l):
        if node is not None:
            self.inOrderSort(node.left, l)  
            l.append(node.val)
            self.inOrderSort(node.right, l)

Log in to reply
 

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