Geek

博客园 首页 新随笔 联系 订阅 管理

 

 

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public TreeNode insertIntoMaxTree(TreeNode root, int val) {
        if(null == root) return new TreeNode(val);
        if(val > root.val) {
            TreeNode n = new TreeNode(val);
            n.left = root;
            return n;
        }
        root.right = insertIntoMaxTree(root.right,val);
        return root;
    }
}

 

posted on 2020-07-15 19:36  .geek  阅读(130)  评论(0编辑  收藏  举报