当前位置:网站首页>Leetcode problem solving - 230 The k-th smallest element in the binary search tree
Leetcode problem solving - 230 The k-th smallest element in the binary search tree
2022-07-03 21:39:00 【Snowy solitary boat】
public int kthSmallest(TreeNode root, int k) {
int i = 1;
Stack<TreeNode> stack = new Stack<>();
TreeNode node = root;
while (!stack.isEmpty()||node!=null){
while (node!=null){
stack.push(node);
node = node.left;
}
node = stack.pop();
if (i==k) return node.val;
i++;
node = node.right;
}
return -1;
}
Ideas : It is improved on the basis of the medium order iteration scheme :
- Judge at the access element , And count
- When i==k, That is, the current number of trees K Element time , Returns the value of the current node
边栏推荐
- Advanced technology management - how to examine candidates in the interview and increase the entry probability
- 90 後,辭職創業,說要卷死雲數據庫
- 浅析 Ref-NeRF
- Yyds dry goods inventory TCP & UDP
- 大神们,我想发两个广播流1 从mysql加载基础数据,广播出去2 从kafka加载基础数据的变更
- Nacos common configuration
- Let me ask you a question. Have you ever used the asynchronous io of Flink SQL to associate dimension tables in MySQL? I set various settings according to the official website
- 17 websites for practicing automated testing. I'm sure you'll like them
- Inventory 2021 | yunyuansheng embracing the road
- "Designer universe" argument: Data Optimization in the design field ultimately falls on cost, safety and health | chinabrand.com org
猜你喜欢

(5) User login - services and processes - History Du touch date stat CP

Borui data and Sina Finance released the 2021 credit card industry development report

Advanced collaboration: coroutinecontext

Décompiler et modifier un exe ou une DLL non source en utilisant dnspy

Leetcode daily question 540 A single element in an ordered array Valentine's Day special article looking for a single dog in a pile of lovers ~ the clown is myself

"Designer universe" APEC safety and health +: environmental protection Panda "xiaobaobao" Happy Valentine's Day 2022 | ChinaBrand | Asia Pacific Economic media

Decompile and modify the non source exe or DLL with dnspy
Implementation principle of inheritance, encapsulation and polymorphism

Transformer structure analysis and the principle of blocks in it

The post-90s resigned and started a business, saying they would kill cloud database
随机推荐
抓包整理外篇——————autoResponder、composer 、statistics [ 三]
运维各常用命令总结
Remember the experience of automatically jumping to spinach station when the home page was tampered with
MySQL——JDBC
Ask and answer: dispel your doubts about the virtual function mechanism
内存分析器 (MAT)
大神们,我想发两个广播流1 从mysql加载基础数据,广播出去2 从kafka加载基础数据的变更
Nacos common configuration
Yiwen teaches you how to choose your own NFT trading market
2022-2-14 acwing1027 grid access
How PHP gets all method names of objects
全网都在疯传的《老板管理手册》(转)
鹏城杯 WEB_WP
QFileDialog
Notes on MySQL related knowledge points (startup, index)
MySQL -- standardize database design
University of Electronic Science and technology | playback of clustering experience effectively used in reinforcement learning
Volley source code analysis
Getting started with postman -- environment variables and global variables
Getting started with postman -- built-in dynamic parameters, custom parameters and assertions