Approach Summary
Level-order using existing next pointers. For each node, link node.left.next = node.right and node.right.next = node.next?.left.
How to Recognize This Pattern
- Perfect binary tree — use next pointers of current level to traverse
- O(1) space: use the level you just connected to build the next
Complexity Analysis
Time Complexity
O(n)
Space Complexity
O(1)
Tags
Linked List Tree DFS BFS Binary Tree