https://leetcode.com/problems/path-sum-ii/
类似112题的思路,只不过判断bool变成数组的和

func pathSum(_ root: TreeNode?, _ sum: Int) -> [[Int]] {
    guard let r = root else { return [] }
    if r.left == nil && r.right == nil {
        return r.val == sum ? [[r.val]] : []
    } else {
        return pathSum(r.left, sum - r.val).map{ [r.val] + $0 } + pathSum(r.right, sum - r.val).map{ [r.val] + $0 }
    }
}

Runtime: 36 ms, faster than 100.00% of Swift online submissions for Path Sum II.
Memory Usage: 20.2 MB, less than 70.00% of Swift online submissions for Path Sum II.