剑指 Offer 26. 树的子结构

https://leetcode-cn.com/problems/shu-de-zi-jie-gou-lcof/

class Solution {
    public boolean isSubStructure(TreeNode A, TreeNode B) {
        return (A != null && B != null) && (recur(A, B) || isSubStructure(A.left, B) || isSubStructure(A.right, B));
    }
    boolean recur(TreeNode A, TreeNode B){
        if(B == null) return true;  //终止条件
        if(A == null || A.val != B.val) return false; //终止条件
        return recur(A.left, B.left) && recur(A.recur, B.right);
    }
}
上一篇:【LeetCode】111. 二叉树的最小深度


下一篇:104. 二叉树的最大深度(c++)