剑指 Offer 26. 树的子结构
作者:互联网
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);
}
}
标签:26,return,recur,Offer,子结构,&&,TreeNode,null,isSubStructure 来源: https://www.cnblogs.com/zhbeii/p/15861259.html