199. Binary Tree Right Side View Medium

@problem@discussion
#Tree#Depth-First Search#Breadth-First Search#Binary Tree



1/**
2 * [199] Binary Tree Right Side View
3 *
4 * Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.
5 *  
6 * Example 1:
7 * <img alt="" src="https://assets.leetcode.com/uploads/2021/02/14/tree.jpg" style="width: 401px; height: 301px;" />
8 * Input: root = [1,2,3,null,5,null,4]
9 * Output: [1,3,4]
10 * 
11 * Example 2:
12 * 
13 * Input: root = [1,null,3]
14 * Output: [1,3]
15 * 
16 * Example 3:
17 * 
18 * Input: root = []
19 * Output: []
20 * 
21 *  
22 * Constraints:
23 * 
24 * 	The number of nodes in the tree is in the range [0, 100].
25 * 	-100 <= Node.val <= 100
26 * 
27 */
28pub struct Solution {}
29use crate::util::tree::{TreeNode, to_tree};
30
31// problem: https://leetcode.com/problems/binary-tree-right-side-view/
32// discuss: https://leetcode.com/problems/binary-tree-right-side-view/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36// Definition for a binary tree node.
37// #[derive(Debug, PartialEq, Eq)]
38// pub struct TreeNode {
39//   pub val: i32,
40//   pub left: Option<Rc<RefCell<TreeNode>>>,
41//   pub right: Option<Rc<RefCell<TreeNode>>>,
42// }
43// 
44// impl TreeNode {
45//   #[inline]
46//   pub fn new(val: i32) -> Self {
47//     TreeNode {
48//       val,
49//       left: None,
50//       right: None
51//     }
52//   }
53// }
54use std::rc::Rc;
55use std::cell::RefCell;
56impl Solution {
57    pub fn right_side_view(root: Option<Rc<RefCell<TreeNode>>>) -> Vec<i32> {
58        vec![]
59    }
60}
61
62// submission codes end
63
64#[cfg(test)]
65mod tests {
66    use super::*;
67
68    #[test]
69    fn test_199() {
70    }
71}
72


Back
© 2025 bowen.ge All Rights Reserved.