Skip to main content
LeetCode 257, Easy. Topics: String, Backtracking, Tree, Depth-First Search, Binary Tree. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 18 parametrized pytest cases, and a playground notebook:

Problem

Given the root of a binary tree, return all root-to-leaf paths in any order. A leaf is a node with no children.

Examples

Example 1

Constraints

  • The number of nodes in the tree is in the range [1, 100].
  • -100 <= Node.val <= 100

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Last modified on September 7, 2026