Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ecf3ada

Browse filesBrowse files
Update 872.py
1 parent 986350e commit ecf3ada
Copy full SHA for ecf3ada

File tree

1 file changed

+13
-0
lines changed
Filter options

1 file changed

+13
-0
lines changed

‎501-1000/872.py

Copy file name to clipboardExpand all lines: 501-1000/872.py
+13Lines changed: 13 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.