1325. 删除给定值的叶子节点 发表于 2021-03-17 | 分类于 leetcode 虚拟节点 + 后序遍历 用时:5min 虚拟节点 + 后序遍历 就可以愉快的秒了 1234567891011121314151617181920var removeLeafNodes = function(root, target) { var dfs = function (root) { if (root.left) { root.left = dfs(root.left) } if (root.right) { root.right = dfs(root.right) } if (!root.left && !root.right) { if (root.val === target) { root = null } } return root } var dummy = new TreeNode(0) dummy.left = root dfs(dummy) return dummy.left};