Skip to content

Added LeetCode Problem No.100#1154

Closed
arnabpal2022 wants to merge 8 commits intoTheAlgorithms:masterfrom
arnabpal2022:origin/test2
Closed

Added LeetCode Problem No.100#1154
arnabpal2022 wants to merge 8 commits intoTheAlgorithms:masterfrom
arnabpal2022:origin/test2

Conversation

@arnabpal2022
Copy link
Copy Markdown

@arnabpal2022 arnabpal2022 commented Nov 20, 2022

Description of Change

References

Checklist

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • I acknowledge that all my contributions will be made under the project's license.

Notes:

@arnabpal2022 arnabpal2022 changed the title Origin/test2 Added LeetCode Problem No.100 Nov 20, 2022
@Panquesito7 Panquesito7 added enhancement New feature or request Leetcode folder changes Changes to Leetcode folder. Known CI issues. labels Nov 21, 2022
Comment thread leetcode/src/100.c Outdated
Comment thread leetcode/src/100.c Outdated
Comment thread leetcode/src/100.c Outdated
Comment on lines +22 to +29
if (p->val == q->val && isSameTree(p->left, q->left) &&
isSameTree(p->right, q->right))
return true;
else
return false;
}
else
return false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;
}

hawkaii
hawkaii previously approved these changes Nov 23, 2022
Copy link
Copy Markdown

@hawkaii hawkaii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no issue seen by me .

Comment thread leetcode/src/100.c Outdated
Comment thread leetcode/src/100.c Outdated
return true;
else if (p && q)
{
if (p->val == q->val && isSameTree(p->left, q->left) &&
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@arnabpal2022
Copy link
Copy Markdown
Author

Check it out guys. if wrong inform me.

Copy link
Copy Markdown
Member

@Panquesito7 Panquesito7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 🚀

Comment thread leetcode/src/100.c

bool isSameTree(struct TreeNode *p, struct TreeNode *q)
{
return (p->val == q->val && isSameTree(p->left, q->left) &&
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we still have to check that p and q are not NULL before

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is necessary. The guard statements are missing, there is no way the recursive function would come to a stop otherwise.

Comment thread leetcode/src/100.c

bool isSameTree(struct TreeNode *p, struct TreeNode *q)
{
return (p->val == q->val && isSameTree(p->left, q->left) &&
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is necessary. The guard statements are missing, there is no way the recursive function would come to a stop otherwise.

@github-actions
Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions bot added the Stale label Feb 18, 2023
@github-actions
Copy link
Copy Markdown
Contributor

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!

@github-actions github-actions bot closed this Feb 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request Leetcode folder changes Changes to Leetcode folder. Known CI issues. Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants