Complete the code to create a vector to store the right side view nodes.
let mut right_view = Vec::[1]();We use Vec::new() to create an empty vector to store the right side view nodes.
Complete the code to push the rightmost node's value into the result vector.
right_view.[1](node.val);We use push to add a single element to the end of the vector.
Fix the error in the recursive call to traverse the right subtree first.
if let Some(right) = node.[1] { dfs(&right, depth + 1, right_view); }
To get the right side view, we must traverse the right child first, so we access node.right.
Fill both blanks to check if current depth equals the vector length and then push the node's value.
if depth == right_view.[1]() { right_view.[2](node.val); }
We compare depth with right_view.len() to see if this is the first node at this depth, then push the value.
Fill all three blanks to complete the DFS function signature and call.
fn dfs(node: &Option<Box<TreeNode>>, [1]: usize, [2]: &mut Vec<i32>) { if let Some(node) = node { if [1] == [2].len() { [2].push(node.val); } dfs(&node.right, [1] + 1, [2]); dfs(&node.left, [1] + 1, [2]); } }
The DFS function takes depth as the current level and right_view as the mutable vector to store values. The call uses these parameters accordingly.
