36.二叉树的中序遍历(递归)

1.代码和解析

cpp 复制代码
class Solution {
public:
   void inorder(TreeNode* root,vector<int> &res){
    if(root==NULL){
        return;
    }
    inorder(root->left,res);
    res.push_back(root->val);
    inorder(root->right,res);
   }
    vector<int> inorderTraversal(TreeNode* root) {
       vector<int> res;
       inorder(root,res);
       return res;
    }
};
相关推荐
旖-旎10 小时前
深搜练习(组合总和)(7)
c++·算法·深度优先·力扣
旖-旎1 天前
深搜练习(组合)(5)
c++·算法·深度优先·力扣
旖-旎2 天前
深搜练习(电话号码字母组合)(3)
c++·算法·力扣·深度优先遍历
加农炮手Jinx5 天前
LeetCode 72. Edit Distance 题解
算法·leetcode·力扣
念越6 天前
算法每日一题 Day08|双指针法解决三数之和
算法·力扣
木子墨5168 天前
LeetCode 热题 100 精讲 | 矩阵与图论进阶篇:矩阵置零 · 螺旋矩阵 · 旋转图像 · 搜索二维矩阵 II · 岛屿数量 · 腐烂的橘子
c++·算法·leetcode·矩阵·力扣·图论
念越8 天前
算法每日一题 Day07|双指针求解和为S的两个数
算法·力扣
旖-旎10 天前
深搜(二叉树剪枝)(3)
数据结构·c++·算法·力扣·剪枝·递归
念越11 天前
算法每日一题 Day05|双指针解决盛最多水的容器问题
算法·力扣
念越12 天前
算法每日一题 Day03|快慢双指针解决快乐树问题
算法·力扣