当前位置:网站首页>415 binary tree (144. preorder traversal of binary tree, 145. postorder traversal of binary tree, 94. inorder traversal of binary tree)
415 binary tree (144. preorder traversal of binary tree, 145. postorder traversal of binary tree, 94. inorder traversal of binary tree)
2022-06-24 10:02:00 【liufeng2023】
144. Preorder traversal of two tree

class Solution
{
public:
void preorder(TreeNode* root, vector<int>& res)
{
if (root == nullptr) return;
res.push_back(root->val);
preorder(root->left, res);
preorder(root->right, res);
}
public:
vector<int> preorderTraversal(TreeNode* root)
{
vector<int> res;
preorder(root, res);
return res;
}
};
class Solution
{
vector<int> res;
public:
void preorder(TreeNode* root)
{
if (root == nullptr) return;
res.push_back(root->val);
preorder(root->left);
preorder(root->right);
}
public:
vector<int> preorderTraversal(TreeNode* root)
{
preorder(root);
return res;
}
};

145. Postorder traversal of binary trees

class Solution
{
vector<int> res;
public:
void preorder(TreeNode* root)
{
if (root == nullptr) return;
preorder(root->left);
preorder(root->right);
res.push_back(root->val);
}
public:
vector<int> postorderTraversal(TreeNode* root)
{
preorder(root);
return res;
}
};

94. Middle order traversal of binary trees

class Solution
{
vector<int> res;
public:
void preorder(TreeNode* root)
{
if (root == nullptr) return;
preorder(root->left);
res.push_back(root->val);
preorder(root->right);
}
public:
vector<int> inorderTraversal(TreeNode* root)
{
preorder(root);
return res;
}
};

边栏推荐
- LeetCode: 240. Search 2D matrix II
- Observer mode
- 操作符详解
- Baidu AI template for knowledge understanding
- 买的长期理财产品,可以转短吗?
- 生产者/消费者模型
- 深度学习论文阅读目标检测篇(七)中英对照版:YOLOv4《Optimal Speed and Accuracy of Object Detection》
- Get the QR code of wechat applet with parameters - and share the source code of modifying the QR code logo
- Idea cannot save settings source root d:xxxx is duplicated in module XXX
- PostgreSQL DBA quick start - source compilation and installation
猜你喜欢

Geogebra instance clock

Servlet快速筑基

In depth study paper reading target detection (VII) Chinese English Bilingual Edition: yolov4 optimal speed and accuracy of object detection

五心红娘

ByteDance Interviewer: talk about the principle of audio and video synchronization. Can audio and video be absolutely synchronized?

5 minutes, excellent customer service chat handling skills

物联网?快来看 Arduino 上云啦

2021-08-17

Indexeddb local storage, homepage optimization

操作符详解
随机推荐
Mise en œuvre du rendu de liste et du rendu conditionnel pour l'apprentissage des applets Wechat.
413-二叉树基础
indexedDB本地存储,首页优化
ByteDance Interviewer: talk about the principle of audio and video synchronization. Can audio and video be absolutely synchronized?
编程题(持续更新)
415-二叉树(144. 二叉树的前序遍历、145. 二叉树的后序遍历、94. 二叉树的中序遍历)
字节跳动-面试官: 谈下音视频同步原理,音频和视频能绝对同步吗?
Why is LNX of e equal to X
使用Live Chat促進業務銷售的驚人技巧
记录一下MySql update会锁定哪些范围的数据
五心红娘
【自定义Endpoint 及实现原理】
linux下oracle服务器打开允许远程连接
桌面软件开发框架大赏
Arbre binaire partie 1
When should gridfs be used?
How to standardize data center infrastructure management process
Is there a reliable and low commission futures account opening channel in China? Is it safe to open an account online?
数组无缝滚动demo
Grpc local test joint debugging tool bloomrpc