Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

path sum with python

# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.left = left
class Solution:
    def hasPathSum(self, root: Optional[TreeNode], targetSum: int) -> bool:
        if root == None:
            return False

        remain = targetSum - root.val

        if remain == 0 and root.left == None and root.right == None:
            return True

        return self.hasPathSum(root.left, remain) or self.hasPathSum(root.right, remain)
Comment

PREVIOUS NEXT
Code Example
Python :: python - convert index to a column 
Python :: python set cwd to file location 
Python :: python pip not working 
Python :: create dict from json file python 
Python :: import xgboost 
Python :: django model plural 
Python :: how can I sort a dictionary in python according to its values? 
Python :: tensorflow history plot 
Python :: how to install pandas datareader in conda 
Python :: python hand tracking module 
Python :: python sort dictionary alphabetically by key 
Python :: wait until clickable selenium python 
Python :: how to count docx pages python 
Python :: jupyter notebook dark theme 
Python :: get number of missing values dataframe 
Python :: python barcode generator 
Python :: check if string url python 
Python :: how to get specific row in pandas 
Python :: how to get ipconfig from python 
Python :: pandas read_csv drop last column 
Python :: how to define a dataframe in python with column name 
Python :: cannot remove column in pandas 
Python :: pip install speedtest 
Python :: use python3 as default ubuntu 
Python :: python gui capture user input 
Python :: pandas group by concat 
Python :: filter list with python 
Python :: python get arguments 
Python :: anaconda python update packages 
Python :: random forest python 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =