```
var sumOfLeftLeaves = function(root) {
var sum = 0;
function rec(node, isLeft) {
if (node) {
// Is a left leaf
if (isLeft && !node.left && !node.right)
sum += node.val;
// Keep traveling down
if (node.right)
rec(node.right, false);
if (node.left)
rec(node.left, true);
}
}
rec(root, false);
return sum;
};
```