Kth Smallest Element in a BST

class Solution:
# @param {TreeNode} root
# @param {integer} k
# @return {integer}
def kthSmallest(self, root, k):
num_left_nodes=self.num_nodes(root.left)
print num_left_nodes
if num_left_nodes+1>k:
return self.kthSmallest(root.left,k)
elif num_left_nodes+1==k:
return root.val
else:
return self.kthSmallest(root.right,k-num_left_nodes-1)
def num_nodes(self,root):
if root is None:
return 0
else:
return self.num_nodes(root.left)+self.num_nodes(root.right)+1


leetcode 230. Kth Smallest Element in a BST-递归|非递归

2016-05-24 11:17:50

leetcode 230: Kth Smallest Element in a BST

2015-07-07 06:14:58

LeetCode 230: Kth Smallest Element in a BST

2015-07-02 14:27:17

LeetCode 230. Kth Smallest Element in a BST 解题报告

2016-02-16 15:27:50

LeetCode-230. Kth Smallest Element in a BST (JAVA)二叉树第k小的数字

2017-04-29 10:36:27

LeetCode 230: Kth Smallest Element in a BST 查找二叉排序树

2015-09-02 15:34:44

230.leetcode Kth Smallest Element in a BST(medium)[二叉搜索树 先序遍历 栈]

2016-08-05 15:46:54

[leetcode] 378. Kth Smallest Element in a Sorted Matrix 解题报告

2016-08-20 15:43:59

[leetcode 230]Kth Smallest Element in a BST----求二叉搜索树的第K小值

2016-03-09 21:51:39

【leetcode】378. Kth Smallest Element in a Sorted Matrix

2016-08-06 13:21:58

不良信息举报

Kth Smallest Element in a BST