Skip to content

Navigation Menu

Sign in
Appearance settings

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

Sign up
Appearance settings

Commit 526cf4d

Browse files
Create 872.py
1 parent 78996cd commit 526cf4d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

‎501-1000/872.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
def findLeaf(root):
10+
if not root:
11+
return []
12+
if not (root.left or root.right):
13+
return [root.val]
14+
return findLeaf(root.left) + findLeaf(root.right)
15+
return findLeaf(root1)==findLeaf(root2)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /