본문 바로가기

카테고리 없음

NeetCode 16번 알고리즘: Binary Tree

Code

class TreeNode:
    def __init__(self, val):
        self.val = val
        self.left = None
        self.right = None

Root, Leaf Nodes

Parent, Children

 

Height, Depth

 

Ancestor, Descendent

Ancestors of 4 : 1,2

Dependent of 2 : 1, 3, 4