Skip to content

j1&j2 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Problems/01-Same-Tree/same_tree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def isSameTree(self, p, q) -> bool:
if not p and not q:
return True
if p and q and p.val == q.val:
return self.isSameTree(p.left,q.left) and self.isSameTree(p.right,q.right)
else:
return False
19 changes: 19 additions & 0 deletions Problems/02-Symmetric-Tree/symmetric_tree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def isSymmetric(self, root) -> bool:
return self.isMirror(root,root)

def isMirror(self,p1,p2) ->bool:
if p1 is None and p2 is None:
return True
if p1 and p2 and p1.val == p2.val:
return self.isMirror(p1.left,p2.right) and self.isMirror(p1.right,p2.left)
else:
return False