230. Kth Smallest Element in a BST
来源:互联网 发布:178软件源地址 编辑:程序博客网 时间:2024/05/22 01:39
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
阅读全文
0 0
- 230.Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- 230. Kth Smallest Element in a BST
- Eclipse解决乱码问题
- Unique Paths II
- 网格离散曲率算法(二次曲面拟合)
- Ubuntu16.04下Mongodb(离线安装方式|非apt-get)安装部署步骤(图文详解)
- POJ 2110 Mountain Walking 笔记
- 230. Kth Smallest Element in a BST
- jsp内置对象
- sobel算子在智能小车巡线中的运用
- 读书笔记《Effective C++》条款44:将与参数无关的代码抽离template
- 第三篇 ME909s-821设备描述符分析
- 最小生成树-Prim算法
- linux 的一些命令
- Java输入输出流详解
- java并行