必威体育Betway必威体育官网
当前位置:首页 > IT技术

bian;i

时间:2019-08-10 14:11:03来源:IT技术作者:seo实验室小编阅读:71次「手机版」
 

bian

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class Solution {
    public TreeNode mergeTrees(TreeNode t1, TreeNode t2) {
        TreeNode root=t2;
        if(t1!=null||t2!=null)
        {
            root=fun(t1,t2);
            root.left=mergeTrees(t1.left,t2.left);
            root.right=mergeTrees(t1.right,t2.right);
        }
        else
        {
            return null;
        }
        return root;
    }
    public TreeNode fun(TreeNode t1, TreeNode t2) {
        TreeNode root=t1;
        if(t1==null&&t2==null)
        {
            return null;
        }
        if(t1!=null||t2!=null)
        {
            if(t1==null)
            {
                root.val=t2.val;
            }
            else if(t2==null)
            {
                root.val=t1.val;
            }
            else
            {
                root.val=t1.val+t2.val;
            }
        }
        return root;
    }
    
    
}
public static void bianli(TreeNode t2)
     {
         while(t2!=null)
         {
             System.out.println(t2.val);
             bianli(t2.left);
             bianli(t2.right);
         }
     }
public class HelloWorld{
 public static class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode(int x) { val = x; }
  }
     public static void main(String []args){
        System.out.println("hello world");
        TreeNode t1=new TreeNode(1);
        t1.left=new TreeNode(3);
        t1.right=new TreeNode(2);
        t1.left.left=new TreeNode(5);
        TreeNode t2=new TreeNode(2);
        t2.left=new TreeNode(1);
        t2.right=new TreeNode(3);
        t1.left.right=new TreeNode(5);
        t1.left.left=new TreeNode(0);
        t2.right.right=new TreeNode(7);
        t2.right.left=new TreeNode(10);
        //TreeNode root=mergeTrees(t1,t2);
        bianli(t2);
     }
     public static void bianli(TreeNode t2)
     {
         while(t2!=null)
         {
             System.out.println(t2.val);
             bianli(t2.left);
             bianli(t2.right);
         }
     }
     public static TreeNode mergeTrees(TreeNode t1, TreeNode t2) {
        TreeNode root=t2;
        while(t1!=null||t2!=null)
        {
            root=fun(t1,t2);
            root.left=mergeTrees(t1.left,t2.left);
            root.right=mergeTrees(t1.right,t2.right);
            System.out.println("Hello World&&&&&&&&&&&&");
        }
        return root;
    }
    public static TreeNode fun(TreeNode t1, TreeNode t2) {
        TreeNode root=t1;
        if(t1!=null||t2!=null)
        {
            if(t1==null)
            {
                root.val=t2.val;
            }
            else if(t2==null)
            {
                root.val=t1.val;
            }
            else
            {
                root.val=t1.val+t2.val;
            }
        }
        return root;
    }
}
public class HelloWorld{
 public static class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode(int x) { val = x; }
  }
     public static void main(String []args){
        System.out.println("Hello World");
        TreeNode t1=new TreeNode(1);
        TreeNode t2=null;
        /*t1.left=new TreeNode(3);
        t1.right=new TreeNode(2);
        t1.left.left=new TreeNode(5);
        TreeNode t2=new TreeNode(2);
        t2.left=new TreeNode(1);
        t2.right=new TreeNode(3);
        t1.left.left=null;
        t2.left.right=new TreeNode(4);
        t2.right.right=new TreeNode(7);
        t2.right.left=null;*/
        TreeNode root=mergeTrees(t1,t2);
        //bianli(t2);
     }
     public static void bianli(TreeNode t2)
     {
         if(t2!=null)
         {
             System.out.println(t2.val);
             bianli(t2.left);
             bianli(t2.right);
         }
     }
     public static TreeNode mergeTrees(TreeNode t1, TreeNode t2) {
        
        if(t1==null&&t2==null)
        {
            return null;
        }
        TreeNode root=new TreeNode(0);
        root.left=null;
        root.right=null;
        if(t1!=null&&t2==null)
        {
            root.val=t1.val;
        }
        else if(t2!=null&&t1==null)
        {
            root.val=t2.val;
        }
        else if(t1!=null&&t2!=null)
        {
            root=fun(t1,t2);
        }
        if(t1.left==null&&t2.left!=null)
        {
            t1.left=new TreeNode(0);
            root.left=mergeTrees(t1.left,t2.left);
        }
        if(t2.left==null&&t1.left!=null)
        {
            t2.left=new TreeNode(0);
            root.left=mergeTrees(t1.left,t2.left);
        }
        if(t1.left!=null&&t2.left!=null)
        {
            root.left=mergeTrees(t1.left,t2.left);
        }
        if(t1.left==null&&t2.left==null)
        {
            root.left=null;
        }
        if(t1.right==null&&t2.right!=null)
        {
            t1.right=new TreeNode(0);
            root.right=mergeTrees(t1.right,t2.right);
        }
        if(t2.right==null&&t1.right!=null)
        {
            t2.right=new TreeNode(0);
            root.right=mergeTrees(t1.right,t2.right);
        }
        if(t1.right!=null&&t2.right!=null)
        {
            root.right=mergeTrees(t1.right,t2.right);
        }
        if(t1.right==null&&t2.right==null)
        {
            root.right=null;
        }
        return root;
    }
    public static TreeNode fun(TreeNode t1, TreeNode t2) {
        TreeNode root=t1;
        if(t1!=null||t2!=null)
        {
            if(t1==null&&t2!=null)
            {
                root.val=t2.val;
                
            }
            else if(t2==null&&t1!=null)
            {
                root.val=t1.val;
            }
            else
            {
                root.val=t1.val+t2.val;
            }
            System.out.println(root.val);
        }
        
        return root;
    }
}

相关阅读

斐讯N1刷armbian

虽然虚拟机也能做 linux 系统,但是如果想带出门的话,带一个笔记本实在是太笨重了。另外,我想自己搞一个类似黑群辉的NAS,用旧笔记本或

biangbiang面怎么写,让你轻松写出美食中的biangbiang面

biangbiang面,陕西特色小吃,biangbiang怎么读,字又怎么写,来看看吧。

9月9日 鞭牛士Bianews关闭PC版网站

网络编辑社区鞭牛士在官网宣布,2015年9月9日正式关闭PC版,将转移到效率更高的移动端——微信。2006年2月14日,三位供职于国内门户网

分享到:

栏目导航

推荐阅读

热门阅读