题解 | #合并两个有序的数组#

实现二叉树先序,中序和后序遍历

http://www.nowcoder.com/practice/a9fec6c46a684ad5a3abd4e365a9d362

class Solution {
public:
    /**
     * 
     * @param root TreeNode类 the root of binary tree
     * @return int整型vector<vector<>>
     */
    vector<int> v1,v2,v3;
    vector<int> first(TreeNode* root){
        if(!root) return v1;
        v1.push_back(root->val);
        first(root->left);
        first(root->right);
        return v1;
    }
    vector<int> mid(TreeNode* root){
        if(!root) return v2;
        mid(root->left);
        v2.push_back(root->val);
        mid(root->right);
        return v2;
    }
    vector<int> last(TreeNode* root){
        if(!root) return v3;
        last(root->left);
        last(root->right);
        v3.push_back(root->val);
        return v3;
    }
    vector<vector<int> > threeOrders(TreeNode* root) {
        // write code here
        vector<vector<int>> v4;
        v4.push_back(first(root));
        v4.push_back(mid(root));
        v4.push_back(last(root));
        return v4;
    }
};
全部评论

相关推荐

码农索隆:单休一个月少休息4天,一年就是48天,平时节假日,别人3天假期,单休的两天
点赞 评论 收藏
分享
Gaynes:查看图片
点赞 评论 收藏
分享
06-17 00:26
门头沟学院 Java
程序员小白条:建议换下项目,智能 AI 旅游推荐平台:https://github.com/luoye6/vue3_tourism_frontend 智能 AI 校园二手交易平台:https://github.com/luoye6/vue3_trade_frontend GPT 智能图书馆:https://github.com/luoye6/Vue_BookManageSystem 选项目要选自己能掌握的,然后最好能自己拓展的,分布式这种尽量别去写,不然你只能背八股文了,另外实习的话要多投,尤其是学历不利的情况下,多找几段实习,最好公司title大一点的
无实习如何秋招上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务