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;
    }
};
相关推荐
语戚5 天前
力扣 1621. 大小为K的不重叠线段的数目:动态规划(Java 实现)
java·算法·leetcode·动态规划·力扣·dp
我不会起名字3228 天前
一天一道算法题(34):回溯法的经典例题(子集)
java·数据结构·python·算法·golang·深度优先·力扣
_Narcissus_25 天前
单调栈笔记及例题详解
数据结构·c++·笔记·算法·力扣·单调栈·洛谷
_Narcissus_1 个月前
链表算法题和静态链表
数据结构·c++·笔记·算法·链表·ai·力扣
玛卡巴卡ldf2 个月前
【LeetCode 手撕算法】(细节知识点总结)
java·数据结构·算法·leetcode·力扣
旖-旎3 个月前
《LeetCode 417 太平洋大西洋水流问题 FloodFill DFS 解法》
c++·算法·深度优先·力扣·floodfill
旖-旎3 个月前
《LeetCode 130 被围绕的区域 FloodFill DFS 解法》
c++·算法·深度优先·力扣·floodfill
旖-旎3 个月前
《LeetCode 695 岛屿的最大面积 FloodFill DFS 解法》
c++·算法·力扣·深度优先遍历·floodfill
旖-旎3 个月前
《LeetCode 200 FloodFill 岛屿数量DFS解法》
c++·算法·深度优先·力扣·floodfill
旖-旎3 个月前
FloodFill(图像渲染)(1)
c++·算法·深度优先·力扣