File tree 1 file changed +4
-25
lines changed
src/main/java/com/fishercoder/solutions 1 file changed +4
-25
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import com .fishercoder .common .classes .TreeLinkNode ;
4
4
5
- /**
6
- * 117. Populating Next Right Pointers in Each Node II
7
- *
8
- * Follow up for problem "Populating Next Right Pointers in Each Node".
9
- * What if the given tree could be any binary tree? Would your previous solution still work?
10
-
11
- Note:
12
-
13
- You may only use constant extra space.
14
- For example,
15
- Given the following binary tree,
16
- 1
17
- / \
18
- 2 3
19
- / \ \
20
- 4 5 7
21
- After calling your function, the tree should look like:
22
- 1 -> NULL
23
- / \
24
- 2 -> 3 -> NULL
25
- / \ \
26
- 4-> 5 -> 7 -> NULL */
27
-
28
5
public class _117 {
29
6
public static class Solution1 {
30
- /**credit: https://discuss.leetcode.com/topic/1106/o-1-space-o-n-complexity-iterative-solution
31
- O(1) space, based on level order traversal*/
7
+ /**
8
+ * credit: https://discuss.leetcode.com/topic/1106/o-1-space-o-n-complexity-iterative-solution
9
+ * O(1) space, based on level order traversal
10
+ */
32
11
public void connect (TreeLinkNode root ) {
33
12
34
13
TreeLinkNode head = null ; //head of the next level
You can’t perform that action at this time.
0 commit comments