':type root: TreeNode
:type v: int
:type d: int
:rtype: TreeNode'

def addOneRow(self, root, v, d):

    if (d in (0, 1)):
        node = TreeNode(v)
        if (d == 1):
            node.left = root
        else:
            node.right = root
        return node
    if (root and (d >= 2)):
        root.left = self.addOneRow(root.left, v, ((d - 1) if (d > 2) else 1))
        root.right = self.addOneRow(root.right, v, ((d - 1) if (d > 2) else 0))
    return root
