Skip to content

Commit f26e679

Browse files
114. Flatten Binary Tree to Linked List (java)
1 parent 5217c9f commit f26e679

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public void flatten(TreeNode root) {
3+
if (root==null) return;
4+
TreeNode right = root.right;
5+
flatten(right);
6+
flatten(root.left);
7+
root.right = root.left;
8+
root.left = null;
9+
TreeNode cache = root;
10+
while (cache.right!=null) cache = cache.right;
11+
cache.right = right;
12+
}
13+
}

0 commit comments

Comments
 (0)