pull/10/head
yuanguangxin 4 years ago
parent 1ae42b25c1
commit ae30f6fa6c

@ -84,6 +84,7 @@
- [q104_二叉树的最大深度](/src/递归/q104_二叉树的最大深度)
- [q226_翻转二叉树](/src/递归/q226_翻转二叉树)
- [q236_二叉树的最近公共祖先](/src/递归/q236_二叉树的最近公共祖先)
- [q1325_删除给定值的叶子节点](/src/递归/q1325_删除给定值的叶子节点)
### 分治法/二分法

@ -84,6 +84,7 @@
- [Question 104 : Maximum Depth of Binary Tree](/src/递归/q104_二叉树的最大深度)
- [Question 226 : Invert Binary Tree](/src/递归/q226_翻转二叉树)
- [Question 236 : Lowest Common Ancestor of a Binary Tree](/src/递归/q236_二叉树的最近公共祖先)
- [Question 1325 : Delete Leaves With a Given Value](/src/递归/q1325_删除给定值的叶子节点)
### Divide and Conquer / Dichotomy

@ -0,0 +1,21 @@
package .q1325_;
/**
* o(n)
*/
public 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;
}
}

@ -0,0 +1,20 @@
package .q1325_;
public class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode() {
}
TreeNode(int val) {
this.val = val;
}
TreeNode(int val, TreeNode left, TreeNode right) {
this.val = val;
this.left = left;
this.right = right;
}
}
Loading…
Cancel
Save