230. Kth Smallest Element in a BST
2017-06-17 21:14
197 查看
My solution with a global variable
class Solution(object): def kthSmallest(self, root, k): """ :type root: TreeNode :type k: int :rtype: int """ self.result = 0 _ = self._tree_count(root, k) return self.result def _tree_count(self, root, k): if not root: return 0 left = self._tree_count(root.left, k) if left + 1 == k: self.result = root.val right = self._tree_count(root.right, k - left - 1) return left + right + 1
相关文章推荐
- Leetcode 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- LeetCode-230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST**
- 230. Kth Smallest Element in a BST
- leetcode 230. Kth Smallest Element in a BST
- Leetcode 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- leetcode_middle_26_230. Kth Smallest Element in a BST
- [leetcode] 230. Kth Smallest Element in a BST
- LeetCode 230. Kth Smallest Element in a BST
- leetcode-java-230. Kth Smallest Element in a BST
- leetcode 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- LeetCode 230. Kth Smallest Element in a BST(二叉搜索树中的第K个元素)
- 【LeetCode】230. Kth Smallest Element in a BST (2 solutions)
- 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST