Submission Detail

225 / 225 test cases passed.
Status:

Accepted

Runtime: 1 ms
Memory Usage: 41.3 MB
Submitted: 0 minutes ago
loading
Runtime Error Message:
Last executed input:
Input:
Output:
Expected:

Accepted Solutions Runtime Distribution

0.0
1.0
2.0
3.0
4.0
5.0
6.0
7.0
8.0
9.0
10.0
65
70
75
80
85
90
java
Runtime (ms)
Distribution (%)

0
1
2
3
4
5
6
7
8
9
10
70
80
90
Zoom area by dragging across this chart

Accepted Solutions Memory Distribution

40250
40500
40750
41000
41250
41500
41750
42000
42250
42500
2
4
6
8
java
You are here!
Your memory usage beats 67.71 % of java submissions.
Memory (KB)
Distribution (%)

40250
40500
40750
41000
41250
41500
41750
42000
42250
42500
5
Zoom area by dragging across this chart

Invite friends to challenge Flatten Binary Tree to Linked List


Submitted Code: 0 minutes ago

Language: java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {
public void flatten(TreeNode root) {
ArrayList<TreeNode> pot = new ArrayList<>();
pot = preOrder(root,pot);
for (int i = 1; i < pot.size(); i++) {
root.left = null;
root.right = pot.get(i);
root = root.right;
}
}
public ArrayList<TreeNode> preOrder(TreeNode root,ArrayList<TreeNode> pot) {
if (root == null)
return pot;
pot.add(root);
pot = preOrder(root.left,pot);
pot = preOrder(root.right,pot);
return pot;
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX