112-Path-Sum

Sat 17 May 2025

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

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def hasPathSum(self, root: TreeNode, summ: int) -> bool:
    if not root:
      return False
    if root.val == summ and not root.left and not root.right:
      return True
    return self.hasPathSum(root.left, summ - root.val) or \
        self.hasPathSum(root.right, summ - root.val)
new Solution().hasPathSum()

Score: 5

Category: leetcode