c++
class Solution {
public:
bool isMatch(TreeNode* A, TreeNode* B) {
if (!B) return true;
if (!A) return false;
if (A->val != B->val) return false;
return isMatch(A->left, B->left) && isMatch(A->right, B->right);
}
bool isSubStructure(TreeNode* A, TreeNode* B) {
if (!B || !A) return false;
if (B->val == A->val && isMatch(A, B)) return true;
return isSubStructure(A->left, B) || isSubStructure(A->right, B);
}
};
js
var isMatch = function(A, B) {
if (!B) return true;
if (!A) return false;
if (A.val == B.val) return isMatch(A.left, B.left) && isMatch(A.right, B.right);
return false;
}
var isSubStructure = function(A, B) {
if (!A || !B) return false;
if (A.val == B.val && isMatch(A, B)) return true;
return isSubStructure(A.left, B) || isSubStructure(A.right, B);
};