Kth Smallest Element in a BST
来源:互联网 发布:python idle使用技巧 编辑:程序博客网 时间:2024/06/08 01:11
Inorder Traverse
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { public int kthSmallest(TreeNode root, int k) { Stack<TreeNode> s = new Stack<TreeNode>(); TreeNode node = root; int result = -1; while (!s.isEmpty() || node != null) { if (node != null) { s.push(node); node = node.left; } else { node = s.pop(); k--; if (k == 0) { return node.val; } node = node.right; } } return result; }}Data Structure Augmentation
0 0
- #leetcode#Kth Smallest Element in a BST
- 230.Kth Smallest Element in a BST
- leetcode--Kth Smallest Element in a BST
- Kth Smallest Element in a BST
- Kth Smallest Element in a BST
- Leetcode|Kth Smallest Element in a BST
- Kth Smallest Element in a BST
- [leetcode] Kth Smallest Element in a BST
- 【LeetCode】Kth Smallest Element in a BST
- Kth Smallest Element in a BST
- LeetCode Kth Smallest Element in a BST
- Kth Smallest Element in a BST
- 【leetcode】Kth Smallest Element in a BST
- Kth Smallest Element in a BST
- Kth Smallest Element in a BST
- LeetCode Kth Smallest Element in a BST
- Kth Smallest Element in a BST
- leetcode: Kth Smallest Element in a BST
- Oracle 定时自动备份(windows任务计划,2016新增linux自动化备份)
- iOS8开发~UI布局(二)storyboard中autolayout和size class的使用详解 f
- Objective-C Runtime 运行时之四:Method Swizzling
- java对象的生命周期及回收
- Cocos2dx开发之锚点实例讲解
- Kth Smallest Element in a BST
- 2015 Multi-University Training Contest 2
- JavaScript启示录
- C++中wstring与string相互转化
- JAVA代码编写规范(摘选)
- Category分类的基本使用
- Linux 发送信号, 修改键映射
- Objective-C Runtime
- AutoLayout(二)