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

Решение

class Solution {
    fun hasPathSum(root: TreeNode?, targetSum: Int): Boolean {
        if (root == null) return false
        val v = root.`val`
        if (root.left == null && root.right == null) return v == targetSum
        val t = targetSum - v
        return hasPathSum(root.left, t) || hasPathSum(root.right, t)
    }
}