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;
    }
};
相关推荐
做人求其滴2 天前
面试经典 150 题 380 274
c++·算法·面试·职场和发展·力扣
Lsk_Smion4 天前
Hot100(开刷) 之 LRU(最近最少使用)缓存
力扣
玛卡巴卡ldf5 天前
【LeetCode 手撕算法】(多维动态规划)不同路径、最小路径和、最长回文子串、最长公共子序列、编辑距离
java·数据结构·算法·leetcode·动态规划·力扣
旖-旎7 天前
深搜练习(单词搜索)(12)
c++·算法·深度优先·力扣
玛卡巴卡ldf8 天前
【LeetCode 手撕算法】(动态规划)爬楼梯、杨辉三角、打家劫舍、完全平方数、零钱兑换、单词拆分、最长递增子序列、乘积最大子数组、分割等和子集
java·数据结构·算法·leetcode·动态规划·力扣
玛卡巴卡ldf11 天前
【LeetCode 手撕算法】(栈)有效括号、最小栈、字符串解码、每日温度、柱状图最大矩形
java·数据结构·算法·leetcode·力扣
小辉同志14 天前
62. 不同路径
c++·力扣·多维动态规划
玛卡巴卡ldf14 天前
【LeetCode 手撕算法】(回溯)全排列DFS、子集、电话号码字母组合 九键、组合总和、括号生成、单词搜索、分割回文数
java·算法·leetcode·力扣
mask哥15 天前
15种算法模式java实现详解
java·算法·力扣
旖-旎18 天前
深搜练习(N皇后)(10)
c++·算法·深度优先·力扣