Skip to content

Instantly share code, notes, and snippets.

@haase1020
Created December 6, 2021 10:57
Show Gist options
  • Save haase1020/0748646b3053dfba615d424fd09c0d2f to your computer and use it in GitHub Desktop.
Save haase1020/0748646b3053dfba615d424fd09c0d2f to your computer and use it in GitHub Desktop.
same tree leetcode #100
// recursive solution: time complexity: O(n) | space complexity: O(h) where h is height of tree (recursion stack)
var isSameTree = function (p, q) {
if (!p && !q) {
return true;
}
if (!p || !q || p.val !== q.val) {
return false;
}
return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment