101. Symmetric Tree Easy
1/**
2 * [101] Symmetric Tree
3 *
4 * Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).
5 *
6 * Example 1:
7 * <img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/symtree1.jpg" style="width: 354px; height: 291px;" />
8 * Input: root = [1,2,2,3,4,4,3]
9 * Output: true
10 *
11 * Example 2:
12 * <img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/symtree2.jpg" style="width: 308px; height: 258px;" />
13 * Input: root = [1,2,2,null,3,null,3]
14 * Output: false
15 *
16 *
17 * Constraints:
18 *
19 * The number of nodes in the tree is in the range [1, 1000].
20 * -100 <= Node.val <= 100
21 *
22 *
23 * Follow up: Could you solve it both recursively and iteratively?
24 */
25pub struct Solution {}
26use crate::util::tree::{TreeNode, to_tree};
27
28// problem: https://leetcode.com/problems/symmetric-tree/
29// discuss: https://leetcode.com/problems/symmetric-tree/discuss/?currentPage=1&orderBy=most_votes&query=
30
31// submission codes start here
32
33// Definition for a binary tree node.
34// #[derive(Debug, PartialEq, Eq)]
35// pub struct TreeNode {
36// pub val: i32,
37// pub left: Option<Rc<RefCell<TreeNode>>>,
38// pub right: Option<Rc<RefCell<TreeNode>>>,
39// }
40//
41// impl TreeNode {
42// #[inline]
43// pub fn new(val: i32) -> Self {
44// TreeNode {
45// val,
46// left: None,
47// right: None
48// }
49// }
50// }
51use std::rc::Rc;
52use std::cell::RefCell;
53impl Solution {
54 pub fn is_symmetric(root: Option<Rc<RefCell<TreeNode>>>) -> bool {
55 false
56 }
57}
58
59// submission codes end
60
61#[cfg(test)]
62mod tests {
63 use super::*;
64
65 #[test]
66 fn test_101() {
67 }
68}
69
Back
© 2025 bowen.ge All Rights Reserved.