HN user

tjscanlon

2 karma
Posts0
Comments3
View on HN
No posts found.

Iterative solution:

    def invertTree(self, root):
        queue = []
        if root is not None:
            queue.append(root)
        while queue:
            current = queue.pop()
            current.left, current.right = current.right, current.left
            if current.left is not None:
                queue.append(current.left)
            if current.right is not None:
                queue.append(current.right)
        return root

Bravo to the CEO for handling it this way. It really shows how treating others like humans and remaining compassionate no matter what the situation is beneficial to everyone.