You are given the root of a binary tree and an integer targetSum. Your task is to determine whether there exists a root-to-leaf path such that the sum of the node values along the path equals targetSum.
A root-to-leaf path is a path that:
Return true if such a path exists; otherwise, return false.
Input: root = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetSum = 22
Output: true
Explanation: The path 5 → 4 → 11 → 2 has a sum of 22.
Input: root = [1,2,3], targetSum = 5
Output: false
Explanation: No root-to-leaf path has a sum of 5.
Input: root = [], targetSum = 0
Output: false
Explanation: The tree is empty, so no root-to-leaf path exists.
Sign in to write, run, and submit your solution against the full test suite.