Back to problems

Binary tree upward path sum

Algorithm · ByteDance · Hard

You are given the root of a binary tree whose nodes store integers, plus an integer targetSum. Decide whether the tree contains some path whose node values add up to exactly targetSum. A path here is a sequence of nodes lying along a single ancestor chain, read from a starting node upward toward its ancestors — each step moves from a node to its parent. The starting node can be anywhere in the tree, not only the root, and a path must contain at least one node, so a single…

Checking your access…