from utils.treeNode import TreeNode

class Solution:
    #O(N) time, O(1) space
    def get_left_leaves_sum(self, node):
        result = 0

        if not node:
            return result

        if node.left and not node.left.left and not node.left.right:
            result += node.left.value
        else:
            result += self.get_left_leaves_sum(node.left)

        result += self.get_left_leaves_sum(node.right)

        return result


node1 = TreeNode(1)
node2 = TreeNode(2)
node3 = TreeNode(3)
node4 = TreeNode(4)
node5 = TreeNode(5)
node6 = TreeNode(6)
node7 = TreeNode(7)

node1.left = node2
node1.right = node3

node2.left = node4
node2.right = node5

node3.left = node6
node6.left = node7

print(node1)
solution = Solution()
print(solution.get_left_leaves_sum(node1))

def left_leaves_sum(root):
    if not root:
        return 0
    
    result = 0
    
    if root.left and not root.left.left and not root.left.right:
        result += root.left.value

    result += left_leaves_sum(root.left) + left_leaves_sum(root.right) 