Last updated 4 years ago
Was this helpful?
the key is recursion.
if root not null return root.value + process-1(root.left) + process-1(root.right)
if root null return 0
const sumTheTreeValues = (root) => { if (root) { return root.value + sumTheTreeValues(root.left) + sumTheTreeValues(root.right); } return 0; };