Path Sum
Easy
Trees
Tree
DFS
Given a binary tree and target sum, return true if root-to-leaf path sum equals target.
Constraints
Nodes ≤ 5000
Examples
Example 1:
Input: 5 4 8 11 null 13 4 7 2 null null null 1
22
Output: true
Example 2:
Input: 1 2 3
5
Output: false
Tests:
Runtime:
Memory:
Test
Input:
Expected:
Got:
Click Run Code to test against sample cases, or Submit to test against all cases.
▲ Console