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 3b6ab55

Browse files
Create 1325.py
1 parent 5e49aa9 commit 3b6ab55

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

‎1001-1500/1325.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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 removeLeafNodes(self, root: Optional[TreeNode], target: int) -> Optional[TreeNode]:
9+
if not root:
10+
return None
11+
root.left = self.removeLeafNodes(root.left, target)
12+
root.right = self.removeLeafNodes(root.right, target)
13+
if not root.left and not root.right and root.val==target:
14+
root = None
15+
return root
16+

0 commit comments

Comments
(0)

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