leetcode 94.二叉树的中序遍历

Posted wegret

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode 94.二叉树的中序遍历相关的知识,希望对你有一定的参考价值。

vector<int> ans;

void dfs(TreeNode* now){
    if (now==nullptr)
        return ;
    dfs(now->left);
    ans.push_back(now->val);
    dfs(now->right);
}

class Solution {
public:
    vector<int> inorderTraversal(TreeNode* root) {
        ans.clear();
        dfs(root);
        return ans;
    }
};

 

以上是关于leetcode 94.二叉树的中序遍历的主要内容,如果未能解决你的问题,请参考以下文章

Leetcode.94.二叉树的中序遍历

LeetCode 94. 二叉树的中序遍历

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

leetcode-94-二叉树的中序遍历

LeetCode Java刷题笔记—94. 二叉树的中序遍历

255.LeetCode | 94. 二叉树的中序遍历