257. Binary Tree Paths
https://leetcode.com/problems/binary-tree-paths/
Python
Javascript
var binaryTreePaths = function(root) {
var result = [];
var backtrack = function(node, n = []) {
if (node) {
n.push(node.val)
if (node.left === null && node.right === null) {
result.push(n.join('->'))
} else {
backtrack(node.left, n.slice(0));
backtrack(node.right, n.slice(0));
}
}
}
backtrack(root);
return result;
};