leetCode.94.94. 二叉树的中序遍历

leetCode.94.94. 二叉树的中序遍历

没什么好讲思路的,直接上代码

cpp 复制代码
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    vector<int> res;
    vector<int> inorderTraversal(TreeNode* root) {
        dfs( root );
        return res;
    }

    void dfs( TreeNode * root ) {
        if ( !root ) return ;

        dfs( root->left );
        res.push_back(root->val);
        dfs( root->right );
    }
};
相关推荐
Swift社区6 小时前
LeetCode 465 最优账单平衡
算法·leetcode·职场和发展
weixin_445054727 小时前
力扣热题51
c++·python·算法·leetcode
smj2302_7968265210 小时前
解决leetcode第3801题合并有序列表的最小成本
数据结构·python·算法·leetcode
sin_hielo13 小时前
leetcode 1975
数据结构·算法·leetcode
2501_9418204913 小时前
面向零信任安全与最小权限模型的互联网系统防护设计思路与多语言工程实践分享
开发语言·leetcode·rabbitmq
2501_9418059313 小时前
一次从接口网关到异步消息驱动架构演化的互联网系统实践技术随笔分享录
leetcode·决策树·贪心算法
黛色正浓14 小时前
leetCode-热题100-二叉树合集(JavaScript)
javascript·算法·leetcode
炽烈小老头15 小时前
【每天学习一点算法 2026/01/05】打乱数组
学习·算法·leetcode
2501_9411497917 小时前
面向微服务异步消息队列与可靠投递的互联网系统高可用设计与多语言工程实践分享
leetcode·决策树
Tisfy17 小时前
LeetCode 1975.最大方阵和:脑筋急转弯
算法·leetcode·矩阵·题解·脑筋急转弯