题解 | #二叉树的中序遍历#

二叉树的中序遍历

https://www.nowcoder.com/practice/0bf071c135e64ee2a027783b80bf781d

class Solution {
public:
    void lur(vector<int>& ret,TreeNode* root)
    {
        if(root == nullptr) return ;
        lur(ret,root->left);
        ret.push_back(root->val);
        lur(ret,root->right);
    }
    vector<int> inorderTraversal(TreeNode* root) {
        // write code here
        vector<int> ret;
        lur(ret,root);
        return ret;
    }
};

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务