标签:
这道题就是数点 divide and conquer
class Solution: # @param {TreeNode} root # @param {integer} k # @return {integer} def kthSmallest(self, root, k): n = self.countNodes(root.left) if k == n + 1: return root.val elif k < n + 1: return self.kthSmallest(root.left, k) else: return self.kthSmallest(root.right, k - n - 1) def countNodes(self, root): if root == None: return 0 return 1 + self.countNodes(root.left) + self.countNodes(root.right)
230 Kth Smallest Element in a BST
标签:
原文地址:http://www.cnblogs.com/dapanshe/p/4625789.html