0
点赞
收藏
分享

微信扫一扫

二叉树--中序遍历

程序员伟杰 2022-10-26 阅读 135


94. Binary Tree Inorder Traversal

Medium

183278FavoriteShare

Given a binary tree, return the inorder traversal of its nodes' values.

Example:

Input: [1,null,2,3]
1
\
2
/
3

Output: [1,3,2]

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

 

举报

相关推荐

0 条评论