-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ashwin B NAIR
committed
Jul 6, 2023
1 parent
b3a254e
commit 5f08b85
Showing
2 changed files
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Solution: | ||
def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool: | ||
if p == None and q == None: | ||
return True | ||
elif p == None or q == None: | ||
return False | ||
if(q.val == p.val): | ||
return self.isSameTree(p.right, q.right) and self.isSameTree(p.left, q.left) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Solution: | ||
def maxDepth(self, root: Optional[TreeNode]) -> int: | ||
if root == None: | ||
return 0 | ||
elif root.right == None and root.left == None: | ||
return 1 | ||
else: | ||
leftHeight = 0 | ||
rightHeight = 0 | ||
if root.right != None: | ||
rightHeight = self.maxDepth(root.right) | ||
if root.left != None: | ||
leftHeight = self.maxDepth(root.left) | ||
return max(leftHeight, rightHeight) + 1 |