https://leetcode.com/problems/path-sum/

func hasPathSum(_ root: TreeNode?, _ sum: Int) -> Bool {
    guard let r = root else { return false }
    if r.left == nil && r.right == nil {
        return r.val == sum
    } else {
        return hasPathSum(r.left, sum - r.val) || hasPathSum(r.right, sum - r.val)
    }
}

Runtime: 40 ms, faster than 100.00% of Swift online submissions for Path Sum.
Memory Usage: 19.4 MB, less than 26.92% of Swift online submissions for Path Sum.