1110. Delete Nodes And Return Forest Medium
1/**
2 * [1110] Delete Nodes And Return Forest
3 *
4 * Given the root of a binary tree, each node in the tree has a distinct value.
5 * After deleting all nodes with a value in to_delete, we are left with a forest (a disjoint union of trees).
6 * Return the roots of the trees in the remaining forest. You may return the result in any order.
7 *
8 * Example 1:
9 * <img alt="" src="https://assets.leetcode.com/uploads/2019/07/01/screen-shot-2019-07-01-at-53836-pm.png" style="width: 237px; height: 150px;" />
10 * Input: root = [1,2,3,4,5,6,7], to_delete = [3,5]
11 * Output: [[1,2,null,4],[6],[7]]
12 *
13 * Example 2:
14 *
15 * Input: root = [1,2,4,null,3], to_delete = [3]
16 * Output: [[1,2,4]]
17 *
18 *
19 * Constraints:
20 *
21 * The number of nodes in the given tree is at most 1000.
22 * Each node has a distinct value between 1 and 1000.
23 * to_delete.length <= 1000
24 * to_delete contains distinct values between 1 and 1000.
25 *
26 */
27pub struct Solution {}
28use crate::util::tree::{TreeNode, to_tree};
29
30// problem: https://leetcode.com/problems/delete-nodes-and-return-forest/
31// discuss: https://leetcode.com/problems/delete-nodes-and-return-forest/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35// Definition for a binary tree node.
36// #[derive(Debug, PartialEq, Eq)]
37// pub struct TreeNode {
38// pub val: i32,
39// pub left: Option<Rc<RefCell<TreeNode>>>,
40// pub right: Option<Rc<RefCell<TreeNode>>>,
41// }
42//
43// impl TreeNode {
44// #[inline]
45// pub fn new(val: i32) -> Self {
46// TreeNode {
47// val,
48// left: None,
49// right: None
50// }
51// }
52// }
53use std::rc::Rc;
54use std::cell::RefCell;
55impl Solution {
56 pub fn del_nodes(root: Option<Rc<RefCell<TreeNode>>>, to_delete: Vec<i32>) -> Vec<Option<Rc<RefCell<TreeNode>>>> {
57 vec![]
58 }
59}
60
61// submission codes end
62
63#[cfg(test)]
64mod tests {
65 use super::*;
66
67 #[test]
68 fn test_1110() {
69 }
70}
71
Back
© 2025 bowen.ge All Rights Reserved.