Java创建单链表(头插法.尾插法),并逆序打印单链表: package day_0324; import java.util.Scanner; import java.util.Stack; class ListNode { int val; ListNode next; public ListNode(int val) { this.val=val; } } public class ListNodeTest { public static void main(String[] args)…
问题描述: 输入两棵二叉树A和B,判断B是不是A的子结构.二叉树结点的定义如下: public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; } } 思路1: 递归 public static boolean HasSubtree(TreeNode root1,TreeNode root2) { boolea…