(function(){ window.OpenPopKa = true;}())

We define a "root-to-leaf path" to be any sequence of nodes in a tree starting with the root node and proceeding downward to a leaf. The "root-to-leaf path sum" for that path is the sum of all the nodes (including the root) along that path. Define an empty tree to contain no root-to-leaf paths (and so its sum is zero). Define a tree with one node to have a root-to-leaf path consisting of just the root (and so its sum is the value of the root). Given a binary tree and a value "sum", return true if the tree has some root-to-leaf path such that adding up all the values along the path equals "sum". Return false if no such path can be found.

[ editor.getValue() ]
if (guess[0] != initEditor) { console.log(guess[0]); window.codeValue = guess[0]; window.progexType= "BTRecurTutor"; window.summexName= "BTpathsumPROG"; } else { return ""; }

If the root is null, and "sum" is zero, then we have success. To return True. Otherwise return False.

We can't pass the sum of the path from the leaf coming up as the return value of the function, because we won't know which child's sum to use. So instead, we have to pass something useful DOWN the tree. In particular, call the children recursively by subtracting the root's value from "sum".

The return value for any non-null node is simply true if and only if at least child returns true.