当前位置:网站首页>leetcode - 230. 二叉搜索树中第K小的元素
leetcode - 230. 二叉搜索树中第K小的元素
2022-06-11 08:28:00 【zmm_mohua】
leetcode - 230. 二叉搜索树中第K小的元素
题目

代码
#include <iostream>
#include <vector>
using namespace std;
typedef struct TreeNode{
int val;
struct TreeNode *left, *right;
}TreeNode, *BiTree;
void create(BiTree &root){
int tn;
cin>>tn;
if(tn == -1){
root = NULL;
return;
}
root = new TreeNode;
root->val = tn;
create(root->left);
create(root->right);
}
vector<int> nums;
void inorder(TreeNode *root){
if(!root){
return;
}
inorder(root->left);
nums.push_back(root->val);
inorder(root->right);
}
int kthSmallest(TreeNode* root, int k) {
inorder(root);
return nums[k-1];
}
int main(){
int k, res;
cin>>k;
TreeNode* root;
create(root);
res = kthSmallest(root, k);
cout<<res;
return 0;
}
边栏推荐
- Modulenotfounderror: no module named 'tensorboard in pytorch‘
- Go language: string connection, digital conversion string
- redis6 入门级教程,有整合案例,可以直接看整合案例,简单入门,直接上手
- Typescript namespace
- Qiao lerna: lerna auxiliary tool
- Js基础学习Script
- Web design and website planning assignment 14 add background music to the video
- Difference between threadpooltaskexecutor and ThreadPoolExecutor
- Type of SQL command (incomplete)
- XXL task executor calls local project
猜你喜欢

uniapp 插件开发

知识图谱入门之---yedda标注

用飞项进行目标管理,不做职场上的“无头苍蝇”

B+ super tree helps you know the underlying structure of MySQL

Qiao lerna: lerna auxiliary tool

Don't want the project out of control? You need to use project management tools
![[software tool] installation ffmpeg](/img/ac/4fbfb3f1a540ec181b94999d9029fb.jpg)
[software tool] installation ffmpeg

Empty difference between postgrepsql and Oracle

Is the result too different from the goal? With the help of target management, you can reach the target accurately!

Qiao NPMS: get the download volume of NPM packages
随机推荐
Typescript header file usage details
How to solve the MySQL deadlock problem? Recitation version
Introduction to database system experiment report answer Experiment 5: database single table query
Bat batch processing separate environment packaging
(resolved) pychart debug error -unicode decodeerror: 'UTF-8' codec can't decode byte 0xe8 in position 1023
Typescript type protection
JS learning basics document Write write a line of text in the page
[programming development] markdown notes tutorial
B+ super tree helps you know the underlying structure of MySQL
Modifying field length in Oracle and postgrepsql
Summary of knowledge points of customized ViewGroup - continuously updated
Modulenotfounderror: no module named 'tensorboard in pytorch‘
Disk format FAT32, exFAT, NTFS of [software tool]
用飞项进行目标管理,不做职场上的“无头苍蝇”
MySQL死锁问题如何解决?背诵版
Type of SQL command (incomplete)
Use of Excel to XML tool of TestLink
Zookepper===> animal management system
Introduction to guava cache usage
SylixOS SD设备驱动开发