[LeetCode]Kth Smallest Element in a BST
2015-11-27 16:33
387 查看
public class Solution { TreeNode result = new TreeNode(0); public int kthSmallest(TreeNode root, int k) { helper(root, k); return result.val; } public int helper(TreeNode root, int k) { if (root == null) { return 0; } int left = helper(root.left, k); if (left == k - 1) { result = root; } int right = helper(root.right, k - left - 1); return left + right + 1; } }
相关文章推荐
- jqury multiselect
- android入门介绍
- 瀑布流布局-初接触
- jQuery EasyUI 布局 - 为网页创建边框布局
- view getMeasuredHeight getHeight区别
- hive与hbase整合
- HDFS快照(HDFS Snapshots)
- js基础——图片切换实例(函数传参)
- switch红色下划线,Error:控制传输跳过的实例化解决办法
- Flume、Kafka、Storm结合
- Dell PowerEdge R710配置raid磁盘阵列
- dubbo + spring + mybaits 的pom文件列一
- 改变android system目录的权限,使修改该目录下的内容。
- 第三步Linux高级编程
- Linux环境下安装weblogc(jar包方式)
- ViewFs Guide
- 自定义UICollectionViewController只读UICollectionViewLayout
- 刷新一张图片的方法
- MySQL垂直和水平切分
- 源码五:HTTP网络的使用