• + 2 comments

    I independently came up with a similar solution for Python:

    def topView(root,side=0):
        if root is None:
            return 0
        if side == 0 or side == -1:
            topView(root.left,side=-1)
        print root.data,
        if side == 0 or side == +1:
            topView(root.right,side=+1)
        return