257. Binary Tree Paths Easy

@problem@discussion
#String#Backtracking#Tree#Depth-First Search#Binary Tree



1/**
2 * [257] Binary Tree Paths
3 *
4 * Given the root of a binary tree, return all root-to-leaf paths in any order.
5 * A leaf is a node with no children.
6 *  
7 * Example 1:
8 * <img alt="" src="https://assets.leetcode.com/uploads/2021/03/12/paths-tree.jpg" style="width: 207px; height: 293px;" />
9 * Input: root = [1,2,3,null,5]
10 * Output: ["1->2->5","1->3"]
11 * 
12 * Example 2:
13 * 
14 * Input: root = [1]
15 * Output: ["1"]
16 * 
17 *  
18 * Constraints:
19 * 
20 * 	The number of nodes in the tree is in the range [1, 100].
21 * 	-100 <= Node.val <= 100
22 * 
23 */
24pub struct Solution {}
25use crate::util::tree::{TreeNode, to_tree};
26
27// problem: https://leetcode.com/problems/binary-tree-paths/
28// discuss: https://leetcode.com/problems/binary-tree-paths/discuss/?currentPage=1&orderBy=most_votes&query=
29
30// submission codes start here
31
32// Definition for a binary tree node.
33// #[derive(Debug, PartialEq, Eq)]
34// pub struct TreeNode {
35//   pub val: i32,
36//   pub left: Option<Rc<RefCell<TreeNode>>>,
37//   pub right: Option<Rc<RefCell<TreeNode>>>,
38// }
39// 
40// impl TreeNode {
41//   #[inline]
42//   pub fn new(val: i32) -> Self {
43//     TreeNode {
44//       val,
45//       left: None,
46//       right: None
47//     }
48//   }
49// }
50use std::rc::Rc;
51use std::cell::RefCell;
52impl Solution {
53    pub fn binary_tree_paths(root: Option<Rc<RefCell<TreeNode>>>) -> Vec<String> {
54        vec![]
55    }
56}
57
58// submission codes end
59
60#[cfg(test)]
61mod tests {
62    use super::*;
63
64    #[test]
65    fn test_257() {
66    }
67}
68


Back
© 2025 bowen.ge All Rights Reserved.