Skip to main content
Medium Trees / DFS Medium frequency

Path Sum II

Open on LeetCode

Approach Summary

DFS with running sum. At each leaf, check if running sum equals target. Backtrack after exploring each child.

How to Recognize This Pattern

  • "All root-to-leaf paths summing to target"
  • Backtracking: add node, recurse, remove on return

Complexity Analysis

Time Complexity

O(n²)

Space Complexity

O(h)

Tags

Backtracking Tree DFS Binary Tree

This site is free. If these guides are helping your prep, consider buying me a coffee. ☕

Support →
Buy me a coffee