首页 > 其他 > 详细

230. Kth Smallest Element in a BST

时间:2018-09-02 11:27:27      阅读:151      评论:0      收藏:0      [点我收藏+]

身体不好

 

 

 

 

 1 class Solution {
 2     public int kthSmallest(TreeNode root, int k) {
 3         Stack<TreeNode> stack = new Stack<TreeNode>();
 4         while(root != null || !stack.empty()) {
 5             while(root != null){
 6                 stack.push(root);
 7                 root = root.left;
 8             }
 9             root = stack.pop();
10             if(--k == 0) return root.val;
11             root = root.right;
12         }
13         return 0;    
14     }
15 }

 

230. Kth Smallest Element in a BST

原文:https://www.cnblogs.com/goPanama/p/9573187.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!