当前位置:网站首页>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
边栏推荐
- Notes on MySQL related knowledge points (startup, index)
- @Transactional注解失效的场景
- Capture de paquets et tri du contenu externe - - autoresponder, composer, statistiques [3]
- How to install sentinel console
- Memory analyzer (MAT)
- 17 websites for practicing automated testing. I'm sure you'll like them
- What if the Flink SQL client exits and the table is emptied?
- MySQL - idea connects to MySQL
- Teach you how to install aidlux (1 installation)
- MySQL——idea连接MySQL
猜你喜欢

What should the future of the Internet be like when Silicon Valley employees flee the big factory and rush to Web3| Footprint Analytics

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

Baohong industry | good habits that Internet finance needs to develop

常用sql集合

Advanced technology management - how to examine candidates in the interview and increase the entry probability

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

Monkey/ auto traverse test, integrate screen recording requirements

90 後,辭職創業,說要卷死雲數據庫

Memory analyzer (MAT)

leetcode-540. A single element in an ordered array
随机推荐
Base ring tree Cartesian tree
MySQL——索引
Xai+ network security? Brandon University and others' latest "interpretable artificial intelligence in network security applications" overview, 33 page PDF describes its current situation, challenges,
Advanced collaboration: coroutinecontext
请教大家一个问题,用人用过flink sql的异步io关联MySQL中的维表吗?我按照官网设置了各种
How to choose cache read / write strategies in different business scenarios?
Compilation Principle -- syntax analysis
Idea shortcut word operation
gslb(global server load balance)技術的一點理解
Intimacy communication -- [repair relationship] - use communication to heal injuries
MySQL - idea connects to MySQL
Luogu deep foundation part 1 Introduction to language Chapter 7 functions and structures
Décompiler et modifier un exe ou une DLL non source en utilisant dnspy
"Designer universe" APEC safety and health +: environmental protection Panda "xiaobaobao" Happy Valentine's Day 2022 | ChinaBrand | Asia Pacific Economic media
2022-02-15 Daily: 2022 AAAI fellow release
UC Berkeley proposes a multitask framework slip
Capturing and sorting out external articles -- autoresponder, composer, statistics [III]
Compréhension de la technologie gslb (Global Server load balance)
How PHP adds two numbers
Why use pycharm to run the use case successfully but cannot exit?