剑指offer--26树的子结构 题目代码结果 题目 代码 class Solution { public boolean isSubStructure(TreeNode A, TreeNode B) { if (B == null || A == null) return false; if (A.val == B.val && (helper(A.left, B.left) && helper(A.right, B.right))) return true; return isSubStructure(A.left, B) || isSubStructure(A.right, B); } private boolean helper(TreeNode root1, TreeNode root2) { if (root2 == null) return true; if (root1 == null) return false; if (root1.val == root2.val) { return helper(root1.left, root2.left) && helper(root1.right, root2.right); } else { return false; } } } 结果