Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

check if binary tree is balanced python

def isBalanced(self, root: Optional[TreeNode]) -> bool:
        def depth(root):
            if not root:
                return 0
            return max(depth(root.left), depth(root.right)) + 1
        def solution(root):
            if not root:
                return True
            if abs(depth(root.left) - depth(root.right)) > 1:
                return False
            return solution(root.left) and solution(root.right)
        return solution(root)
Comment

PREVIOUS NEXT
Code Example
Python :: stackoverflow python 
Python :: Write a simple python program that adds 2 numbers togethe 
Python :: how to pass primary key to url django 
Python :: mid point circle drawing 
Python :: python c like struct 
Python :: using python for rest api 
Python :: shared SHMEM python 
Python :: make array consecutive 2 python 
Python :: The MEDIA_URL setting must end with a slash. 
Python :: python regex find single character 
Python :: iterrows pd 
Python :: Display shape of the DataFrame 
Python :: import modules given the full path python 
Python :: random forest classifier classification report 
Python :: how to implement heap in python 
Python :: qt designer python 
Python :: save a preprocess text 
Python :: python book 
Python :: {} string python 
Python :: boder color in tkinter 
Python :: Selenium get response body python 
Python :: python selenium click on agree button 
Python :: requirements.txt dev python 
Python :: if-else Conditional Statement in Python 
Python :: how to change series datatype from object to float 
Python :: how to define number in python 
Python :: django run manage.py from python 
Python :: pandas fill missing index values 
Python :: how to get one record in django 
Python :: true and false in python 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =