题目:
给定一个二叉搜索树的根节点root,和一个整数k,请你设计一个算法查找其中第k个最小元素(从 1 开始计数)服务器托管网。
示例 1:
输入服务器托管网:root = [3,1,4,null,2], k = 1
输出:1
示例 2:
输入:root = [5,3,6,2,4,null,null,1], k = 3
输出:3
代码实现:
class Solution {
public int kthSmallest(TreeNode root, int k) {
Deque stack = new ArrayDeque();
while (root != null || !stack.isEmpty()) {
while (root != null) {
stack.push(root);
root = root.left;
}
root = stack.pop();
--k;
if (k == 0) {
break;
}
root = root.right;
}
return root.val;
}
}
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.fwqtg.net
— SELECT * FROM t_videoTalkRecord; — SELECT * FROM t_videoTalkRecord WHERE id IN (SELECT max(id) — FROM t_videoTalkRecord GROUP…