Medium · Trees

Path sum to K

Given the root of a binary tree and an integer k, return the number of downward paths whose node values sum to k. A path may start and end at any nodes, including a single node, but must run from parent to child.

Examples

Example 1

tree=[10,5,-3,3,2,null,11], k=8

Output: 2 paths

Example 2

tree=[7,4,2,3,null,5,null], k=7

Output: 3 paths

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Trees problems