AcWing
  • 首页
  • 题库
  • 题解
  • 分享
  • 问答
  • 活动
  • 应用
  • 吐槽
  • 登录/注册

LeetCode 面试题 17.12. BiNode【好】    原题链接    简单

作者: 作者的头像   开水白菜 ,  2021-01-23 08:10:58 ,  阅读 32


0


/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    TreeNode* pre;
    TreeNode* dumpy;
    TreeNode* convertBiNode(TreeNode* root) {
        pre = new TreeNode(-1);
        dumpy = pre;
        inorder(root);
        return dumpy->right;
    }
    void inorder(TreeNode* root){
        if(root == NULL) return ;
        inorder(root->left);
        pre->right = root;
        root->left = nullptr;
        pre = root;
        inorder(root->right);
    }
};

0 评论

你确定删除吗?

© 2018-2021 AcWing 版权所有  |  京ICP备17053197号-1
联系我们  |  常见问题
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标
请输入绑定的邮箱地址
请输入注册信息