Created
May 27, 2014 09:11
-
-
Save honux77/eaabe0c4dec0d2561b95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://oj.leetcode.com/problems/populating-next-right-pointers-in-each-node/