forked from Azureki/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlc872.py
50 lines (33 loc) · 903 Bytes
/
lc872.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
def leafSimilar(self, root1, root2):
"""
:type root1: TreeNode
:type root2: TreeNode
:rtype: bool
"""
L1=[]
L2=[]
self.findLeaf(root1,L1)
self.findLeaf(root2,L2)
# print(L1)
# print(L2)
return L1 == L2
def findLeaf(self,root,L):
print(root.left,root.right)
if not(root.left or root.right):
print('yes')
L.append(root.val)
print(L)
if root.left:
self.findLeaf(root.left,L)
if root.right:
self.findLeaf(root.right,L)
root1=TreeNode(1)
root2=TreeNode(2)
sol=Solution()
print(sol.leafSimilar(root1,root2))