当前位置:网站首页>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
边栏推荐
- Software testing skills, JMeter stress testing tutorial, obtaining post request data in x-www-form-urlencoded format (24)
- 2022-2-14 acwing1027 grid access
- gslb(global server load balance)技術的一點理解
- MySQL - idea connects to MySQL
- Pengcheng cup Web_ WP
- 浅析 Ref-NeRF
- 90 后,辞职创业,说要卷死云数据库
- Study diary: February 14th, 2022
- 17 websites for practicing automated testing. I'm sure you'll like them
- Global and Chinese market of recycled yarn 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

仿网易云音乐小程序

MySQL——JDBC

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

Hcie security Day11: preliminarily learn the concepts of firewall dual machine hot standby and vgmp

使用dnSpy對無源碼EXE或DLL進行反編譯並且修改

MySQL - idea connects to MySQL

Minio deployment

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

How PHP drives mongodb

Compilation Principle -- syntax analysis
随机推荐
仿网易云音乐小程序
Capturing and sorting out external articles -- autoresponder, composer, statistics [III]
MySQL——JDBC
Décompiler et modifier un exe ou une DLL non source en utilisant dnspy
UI automation test: selenium+po mode +pytest+allure integration
鹏城杯 WEB_WP
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
Etcd raft Based Consistency assurance
Pengcheng cup Web_ WP
Remember the experience of automatically jumping to spinach station when the home page was tampered with
Getting started with postman -- environment variables and global variables
全网都在疯传的《老板管理手册》(转)
QFileDialog
抓包整理外篇——————autoResponder、composer 、statistics [ 三]
Install and use Chrony, and then build your own time server
[gd32l233c-start] 5. FLASH read / write - use internal flash to store data
gslb(global server load balance)技術的一點理解
@Scenario of transactional annotation invalidation
Volley source code analysis
Compréhension de la technologie gslb (Global Server load balance)