Wednesday, October 15, 2014

Populating Next Right Pointers in Each Node II

Problem

Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tree could be any binary tree? Would your previous solution still work? Note: You may only use constant extra space. For example, Given the following binary tree, After calling your function, the tree should look like:

Idea

用队列来帮助遍历,用NULL来隔断每一层

Solution


No comments:

Post a Comment