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;
    }
};
相关推荐
_Narcissus_5 天前
单调栈笔记及例题详解
数据结构·c++·笔记·算法·力扣·单调栈·洛谷
_Narcissus_8 天前
链表算法题和静态链表
数据结构·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++·算法·深度优先·力扣
帅小伙―苏3 个月前
239. 滑动窗口最大值
python·力扣
语戚3 个月前
力扣 3161. 块放置查询:线段树解法(Java 实现)
java·算法·leetcode·面试·线段树·力扣·