Added LeetCode Problem No.100#1154
Added LeetCode Problem No.100#1154arnabpal2022 wants to merge 8 commits intoTheAlgorithms:masterfrom arnabpal2022:origin/test2
Conversation
| if (p->val == q->val && isSameTree(p->left, q->left) && | ||
| isSameTree(p->right, q->right)) | ||
| return true; | ||
| else | ||
| return false; | ||
| } | ||
| else | ||
| return false; |
There was a problem hiding this comment.
| if (p->val == q->val && isSameTree(p->left, q->left) && | |
| isSameTree(p->right, q->right)) | |
| return true; | |
| else | |
| return false; | |
| } | |
| else | |
| return false; | |
| if (p->val == q->val && isSameTree(p->left, q->left) && | |
| isSameTree(p->right, q->right)) { | |
| return true; | |
| } | |
| else { | |
| return false; | |
| } | |
| } | |
| else { | |
| return false; | |
| } |
| return true; | ||
| else if (p && q) | ||
| { | ||
| if (p->val == q->val && isSameTree(p->left, q->left) && |
There was a problem hiding this comment.
what if to use the folllowing:
return( p->val == q->val && isSameTree(p->left, q->left) &&
isSameTree(p->right, q->right));
instead of this whole if?
Co-authored-by: David Leal <halfpacho@gmail.com>
|
Check it out guys. if wrong inform me. |
|
|
||
| bool isSameTree(struct TreeNode *p, struct TreeNode *q) | ||
| { | ||
| return (p->val == q->val && isSameTree(p->left, q->left) && |
There was a problem hiding this comment.
we still have to check that p and q are not NULL before
There was a problem hiding this comment.
@arnabpal2022 I would probably use something like this:
// both NULL - nodes are equal this case.
if (p == NULL && q == NULL) {
return true;
}
// Just one of nodes is NULL. Nodes are not equal
if (p == NULL || q == NULL){
return false;
}
// Main condition that vals are equal, and recursive check.
return p->val == q->val
&& isSameTree(p->left, q->left)
&& isSameTree(p->right, q->right);There was a problem hiding this comment.
Yes this is necessary. The guard statements are missing, there is no way the recursive function would come to a stop otherwise.
|
|
||
| bool isSameTree(struct TreeNode *p, struct TreeNode *q) | ||
| { | ||
| return (p->val == q->val && isSameTree(p->left, q->left) && |
There was a problem hiding this comment.
Yes this is necessary. The guard statements are missing, there is no way the recursive function would come to a stop otherwise.
|
This pull request has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
Please ping one of the maintainers once you commit the changes requested or make improvements on the code. If this is not the case and you need some help, feel free to ask for help in our Gitter channel or our Discord server. Thank you for your contributions! |
Description of Change
References
Checklist
Notes: