/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
bool match_one(struct TreeNode* A, struct TreeNode* B) {
if (A == NULL) return B == NULL;
if (B == NULL) return true;
if (A->val != B->val) return false;
return match_one(A->left, B->left) && match_one(A->right, B->right);
}
bool isSubStructure(struct TreeNode* A, struct TreeNode* B) {
if (A == NULL || B == NULL) return false;
if (A->val == B->val && match_one(A, B)) return true;
if (isSubStructure(A->left, B)) return true;
if (isSubStructure(A->right, B)) return true;
return false;
}
leetcode-LCR 143:子结构判断
最新推荐文章于 2024-09-16 06:54:08 发布