二叉树那个题应该是这样吧 let temp; let result; function FindPath(root) { temp = []; result = []; if (root == null) { return []; } find(root); let sum = 0; for(let item of result){ sum += Number(item.join("")); } console.log(sum); } function find(root) { temp.push(root.value); if (root.left == null && root.right == null) { result.push(temp.slice()); } else { if (root.left != null) { find(root.left); } if (root.right != null) { find(root.right); } } temp.pop(); } FindPath(tree)