Kth Smallest Element in a BST
来源:互联网 发布:c语言竖线 编辑:程序博客网 时间:2024/06/05 02:44
/** * 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) { if (root == null) { return 0; } Stack<TreeNode> stack = new Stack<>(); stack.push(root); int i = 0; while (!stack.isEmpty()) { TreeNode node = stack.peek(); if (node.left != null) { stack.push(node.left); node.left = null; } else { stack.pop(); i++; if (i == k) { return node.val; } if (node.right != null) { stack.push(node.right); } } } return 0; }}
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
- 在centos中键入不同终端的几种方法
- Android使用AttributeSet自定义控件的方法
- Factor Combinations
- 演示MP3的复制。通过IO流缓冲区。
- 【转载】逃离adapter的地狱-针对多个View type的组合实现方案
- Kth Smallest Element in a BST
- Map获取键值的几种遍历方法
- 通过火车票还原身份证
- CodeForces 686B 冒泡排序
- Codeforces700A As Fast As Possible 数学推理
- Python异常处理机制
- 欧拉函数求法与应用
- Servlet整合Log4j日志记录
- HDU Problem 1052 Tian Ji -- The Horse Racing 【贪心】