Skip to content

Instantly share code, notes, and snippets.

@MohammedALREAI
Created March 5, 2021 13:36
Show Gist options
  • Select an option

  • Save MohammedALREAI/408d82b06c3b3eb824b4b3f964f71828 to your computer and use it in GitHub Desktop.

Select an option

Save MohammedALREAI/408d82b06c3b3eb824b4b3f964f71828 to your computer and use it in GitHub Desktop.
100. Same Tree leetcode
// /
// Definition for a binary tree node.
class TreeNode {
val: number
left: TreeNode | null
right: TreeNode | null
constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {
this.val = (val===undefined ? 0 : val)
this.left = (left===undefined ? null : left)
this.right = (right===undefined ? null : right)
}
}
function isSameTree(p: TreeNode | null, q: TreeNode | null): boolean {
if(!p &&!q) return true
else if(!p||!q) return false
else if(p.val !==q.val) return false
else {
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