Skip to content

Instantly share code, notes, and snippets.

@honux77
Created May 27, 2014 09:11
Show Gist options
  • Select an option

  • Save honux77/eaabe0c4dec0d2561b95 to your computer and use it in GitHub Desktop.

Select an option

Save honux77/eaabe0c4dec0d2561b95 to your computer and use it in GitHub Desktop.
/**
* https://oj.leetcode.com/problems/populating-next-right-pointers-in-each-node/
* Definition for binary tree with next pointer.
* public class TreeLinkNode {
* int val;
* TreeLinkNode left, right, next;
* TreeLinkNode(int x) { val = x; }
* }
*/
public class Solution {
public void connect(TreeLinkNode root) {
if (root == null) return;
if (root.left != null)
root.left.next = root.right;
if (root.right != null)
root.right.next = (root.next == null) ? null : root.next.left;
connect(root.left);
connect(root.right);
}
}
@honux77
Copy link
Copy Markdown
Author

honux77 commented May 27, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment