':type root: TreeNode
:rtype: List[int]'

def largestValues(self, root):

    def largestValuesHelper(root, depth, result):
        if (not root):
            return
        if (depth == len(result)):
            result.append(root.val)
        else:
            result[depth] = max(result[depth], root.val)
        largestValuesHelper(root.left, (depth + 1), result)
        largestValuesHelper(root.right, (depth + 1), result)
    result = []
    largestValuesHelper(root, 0, result)
    return result
