Populating Next Right Pointers in Each Node

recursion programming

画图看特点

 1 public class Solution {
 2     public void connect(TreeLinkNode root) {
 3         // IMPORTANT: Please reset any member data you declared, as
 4         // the same Solution instance will be reused for each test case.
 5         if(root == null)
 6             return;
 7         if(root.left != null)
 8             root.left.next = root.right;
 9         if(root.right != null)
10             root.right.next = root.next == null?null:root.next.left;
11         connect(root.left);
12         connect(root.right);
13     }
14 }
原文地址:https://www.cnblogs.com/jasonC/p/3417858.html