# Binary tree level order traversal algoritm

I am trying to solve this Binary tree lever order traversal:

Given binary tree {3,9,20,#,#,15,7},
3
/ \
9  20
/  \
15   7
return its bottom-up level order traversal as:
[
[15,7]
[9,20],
[3],
]


How can I improve the speed of the code below? It always gives me a time exceed error.

/**
* Definition for binary tree
* public class TreeNode {
*     int val;
*     TreeNode left;
*     TreeNode right;
*     TreeNode(int x) { val = x; }
* }
*/
public class Solution {

public ArrayList<ArrayList<Integer>> levelOrderBottom(TreeNode root) {
ArrayList<ArrayList<Integer>> tree = new ArrayList<ArrayList<Integer>>();
Stack<Integer> stack = new Stack<Integer>();
ArrayList<Integer> node = new ArrayList<Integer>();

this.iterateAll(root, stack);

while (!stack.empty()) {
if (stack.peek() != null) {
if (!stack.isEmpty()) {
if (stack.peek() != null) {
node = new ArrayList<Integer>();
} else {
stack.pop();
if (!stack.isEmpty()) {
if (stack.peek() != null) {
node = new ArrayList<Integer>();
}
}
}
} else {
}
} else {
stack.pop();
}
}
return tree;
}

public Stack<Integer> iterateAll(TreeNode root, Stack<Integer> stack) {
if (root != null) {
stack.push(root.val);
if (root.right != null) {
iterateAll(root.right, stack);
} else {
stack.push(null);
}

if (root.left != null) {
iterateAll(root.left, stack);
} else {
stack.push(null);
}
}
return stack;
}
}