# 1325. Delete Leaves With a Given Value ###### tags: `Leetcode` `Medium` `Bloomberg` `DFS` Link: https://leetcode.com/problems/delete-leaves-with-a-given-value/ ## Code ```java= class Solution { public TreeNode removeLeafNodes(TreeNode root, int target) { if(root == null) return null; root.left = removeLeafNodes(root.left, target); root.right = removeLeafNodes(root.right, target); if(root.val == target && root.left == null && root.right == null) return null; return root; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up