230. Kth Smallest Element in a B
作者:
夜皇雪 | 来源:发表于
2016-12-12 06:14 被阅读0次/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
private int count=0;
private int res=0;
public int kthSmallest(TreeNode root, int k) {
count=k;
helper(root);
return res;
}
public void helper(TreeNode root){
if(root.left!=null) helper(root.left);
count--;
if(count==0){
res=root.val;
return;
}
if(root.right!=null) helper(root.right);
}
}
本文标题:230. Kth Smallest Element in a B
本文链接:https://www.haomeiwen.com/subject/iaqmmttx.html
网友评论