# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def removeLeafNodes(self, root: Optional[TreeNode], target: int) -> Optional[TreeNode]:
def travel(node):
if node:
node.left = travel(node.left)
node.right = travel(node.right)
if not node.left and not node.right and node.val == target:
# Return none to delete node if leaf node matches target value
return None
return node
return travel(root)