Python Solution With Explaintion
I want to share how I come up with this solution with you:\n\nSince we are manipulating tree nodes on the same level, it's easy to come up with\na very standard
I want to share how I come up with this solution with you:\n\nSince we are manipulating tree nodes on the same level, it's easy to come up with\na very standard BFS solution using  queue.  But because of next pointer, we actually\ndon't  need a queue to store the order of tree nodes at each level, we just use a next\npointer like it's a link list at each level;  In addition, we can borrow the idea used  in\nthe Binary Tree level order traversal problem, which use cur and next pointer to store \nfirst node at each level; we exchange cur and next every time when cur is the last node\nat each level. \n\n\n      class Solution(object):\n        def connect(self, root):\n            """\n            :type root: TreeLinkNode\n            :rtype: nothing\n            """\n            \n            if not root:\n                return None\n            cur  = root\n            next = root.left\n    \n            while cur.left :\n                cur.left.next = cur.right\n                if cur.next:\n                    cur.right.next = cur.next.left\n                    cur = cur.next\n                else:\n                    cur = next\n                    next = cur.left
['Python']