Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Sum Root to Leaf Numbers

Medium

Topics
TreeDFS

Each root-to-leaf path in a binary tree represents a number formed by concatenating the node digits (each node value is a single digit 0-9). Return the total sum of all root-to-leaf numbers.

Example 1

Input:  root = [1,2,3]
Output: 25
Explanation: Paths 12 and 13; 12 + 13 = 25.

Example 2

Input:  root = [4,9,0,5,1]
Output: 1026

Constraints

  • 1 <= number of nodes <= 1000
  • 0 <= Node.val <= 9
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access