872. Leaf-Similar Trees Easy
1/**
2 * [872] Leaf-Similar Trees
3 *
4 * Consider all the leaves of a binary tree, from left to right order, the values of those leaves form a leaf value sequence.
5 * <img alt="" src="https://s3-lc-upload.s3.amazonaws.com/uploads/2018/07/16/tree.png" style="width: 400px; height: 336px;" />
6 * For example, in the given tree above, the leaf value sequence is (6, 7, 4, 9, 8).
7 * Two binary trees are considered leaf-similar if their leaf value sequence is the same.
8 * Return true if and only if the two given trees with head nodes root1 and root2 are leaf-similar.
9 *
10 * Example 1:
11 * <img alt="" src="https://assets.leetcode.com/uploads/2020/09/03/leaf-similar-1.jpg" style="width: 600px; height: 237px;" />
12 * Input: root1 = [3,5,1,6,2,9,8,null,null,7,4], root2 = [3,5,1,6,7,4,2,null,null,null,null,null,null,9,8]
13 * Output: true
14 *
15 * Example 2:
16 * <img alt="" src="https://assets.leetcode.com/uploads/2020/09/03/leaf-similar-2.jpg" style="width: 300px; height: 110px;" />
17 * Input: root1 = [1,2,3], root2 = [1,3,2]
18 * Output: false
19 *
20 *
21 * Constraints:
22 *
23 * The number of nodes in each tree will be in the range [1, 200].
24 * Both of the given trees will have values in the range [0, 200].
25 *
26 */
27pub struct Solution {}
28use crate::util::tree::{TreeNode, to_tree};
29
30// problem: https://leetcode.com/problems/leaf-similar-trees/
31// discuss: https://leetcode.com/problems/leaf-similar-trees/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 leaf_similar(root1: Option<Rc<RefCell<TreeNode>>>, root2: Option<Rc<RefCell<TreeNode>>>) -> bool {
57 false
58 }
59}
60
61// submission codes end
62
63#[cfg(test)]
64mod tests {
65 use super::*;
66
67 #[test]
68 fn test_872() {
69 }
70}
71
Back
© 2025 bowen.ge All Rights Reserved.