Skip to content

Commit ecf3ada

Browse files
Update 872.py
1 parent 986350e commit ecf3ada

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

501-1000/872.py

+13
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,16 @@ def findLeaf(root):
1313
return [root.val]
1414
return findLeaf(root.left) + findLeaf(root.right)
1515
return findLeaf(root1)==findLeaf(root2)
16+
17+
18+
19+
class Solution:
20+
def leafSimilar(self, root1: Optional[TreeNode], root2: Optional[TreeNode]) -> bool:
21+
def dfs(root):
22+
if not root:
23+
return []
24+
if not root.left and not root.right:
25+
return [root.val]
26+
return dfs(root.left) + dfs(root.right)
27+
return dfs(root2)==dfs(root1)
28+

0 commit comments

Comments
 (0)