951. Flip Equivalent Binary Trees Medium
1/**
2 * [951] Flip Equivalent Binary Trees
3 *
4 * For a binary tree T, we can define a flip operation as follows: choose any node, and swap the left and right child subtrees.
5 * A binary tree X is flip equivalent to a binary tree Y if and only if we can make X equal to Y after some number of flip operations.
6 * Given the roots of two binary trees root1 and root2, return true if the two trees are flip equivalent or false otherwise.
7 *
8 * Example 1:
9 * <img alt="Flipped Trees Diagram" src="https://assets.leetcode.com/uploads/2018/11/29/tree_ex.png" style="width: 500px; height: 220px;" />
10 * Input: root1 = [1,2,3,4,5,6,null,null,null,7,8], root2 = [1,3,2,null,6,4,5,null,null,null,null,8,7]
11 * Output: true
12 * Explanation: We flipped at nodes with values 1, 3, and 5.
13 *
14 * Example 2:
15 *
16 * Input: root1 = [], root2 = []
17 * Output: true
18 *
19 * Example 3:
20 *
21 * Input: root1 = [], root2 = [1]
22 * Output: false
23 *
24 *
25 * Constraints:
26 *
27 * The number of nodes in each tree is in the range [0, 100].
28 * Each tree will have unique node values in the range [0, 99].
29 *
30 */
31pub struct Solution {}
32use crate::util::tree::{TreeNode, to_tree};
33
34// problem: https://leetcode.com/problems/flip-equivalent-binary-trees/
35// discuss: https://leetcode.com/problems/flip-equivalent-binary-trees/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39// Definition for a binary tree node.
40// #[derive(Debug, PartialEq, Eq)]
41// pub struct TreeNode {
42// pub val: i32,
43// pub left: Option<Rc<RefCell<TreeNode>>>,
44// pub right: Option<Rc<RefCell<TreeNode>>>,
45// }
46//
47// impl TreeNode {
48// #[inline]
49// pub fn new(val: i32) -> Self {
50// TreeNode {
51// val,
52// left: None,
53// right: None
54// }
55// }
56// }
57use std::rc::Rc;
58use std::cell::RefCell;
59impl Solution {
60 pub fn flip_equiv(root1: Option<Rc<RefCell<TreeNode>>>, root2: Option<Rc<RefCell<TreeNode>>>) -> bool {
61 false
62 }
63}
64
65// submission codes end
66
67#[cfg(test)]
68mod tests {
69 use super::*;
70
71 #[test]
72 fn test_951() {
73 }
74}
75
Back
© 2025 bowen.ge All Rights Reserved.