Skip to content

Commit fb5f317

Browse files
committed
Time: 42 ms (17.45%) | Memory: 16.4 MB (74.73%) - LeetSync
1 parent 1866c9c commit fb5f317

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Definition for a binary tree node.
2+
# class TreeNode:
3+
# def __init__(self, val=0, left=None, right=None):
4+
# self.val = val
5+
# self.left = left
6+
# self.right = right
7+
class Solution:
8+
def leafSimilar(self, root1: Optional[TreeNode], root2: Optional[TreeNode]) -> bool:
9+
10+
def helper(root, ans):
11+
if not root:
12+
return
13+
if root and not root.left and not root.right:
14+
ans.append(root.val)
15+
return
16+
17+
helper(root.left,ans)
18+
helper(root.right,ans)
19+
ans1 = []
20+
ans2 = []
21+
22+
helper(root1,ans1)
23+
helper(root2, ans2)
24+
print(ans1, ans2)
25+
return ans1 == ans2
26+
27+
28+
29+

0 commit comments

Comments
 (0)