Created
March 5, 2021 13:36
-
-
Save MohammedALREAI/408d82b06c3b3eb824b4b3f964f71828 to your computer and use it in GitHub Desktop.
100. Same Tree leetcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // / | |
| // 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