# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def hasPathSum(self, root: Optional[TreeNode], targetSum: int) -> bool:
if not root:
return False
if not root.left and not root.right and root.val == targetSum:
return True
return self.hasPathSum(root.left,targetSum - root.val) or self.hasPathSum(root.right,targetSum - root.val)
訂單已配對司機
Feb 22, 2025鄰接矩陣 (Adjacent Matrix)
May 12, 2024透過標記已訪問過的島嶼為 “2” 來遍歷是否為同一個島嶼
Apr 19, 2024逐一計算 class Solution: def islandPerimeter(self, grid: List[List[int]]) -> int: xc,yc = len(grid[0]), len(grid) output = 0 for y in range(yc): for x in range(xc): if grid[y][x] == 1: borders = 4 if x >= 1:
Apr 18, 2024or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up