public static ArrayList<ArrayList<Integer>> levelOrderBottom(TreeNode root) {
		if (root == null) {
			return new ArrayList<ArrayList<Integer>>();
		}
		ArrayList<ArrayList<Integer>> rows = new ArrayList<ArrayList<Integer>>();

		int idx = 0;
		TreeNode[] xs = new TreeNode[10];
		TreeNode[] ys = new TreeNode[10];
		xs[idx++] = root;

		while (idx > 0) {
			ArrayList<Integer> row = new ArrayList<Integer>();
			int len = idx;
			idx = 0;

			for (int i = 0; i < len; i++) {
				TreeNode x = xs[i];
				row.add(x.val);

				if (idx >= ys.length - 2) {
					ys = Arrays.copyOf(ys, idx + 10);
				}

				if (x.left != null) {
					ys[idx++] = x.left;
				}
				if (x.right != null) {
					ys[idx++] = x.right;
				}
			}

			rows.add(row);
			TreeNode[] tmp = xs;
			xs = ys;
			ys = tmp;
		}

		Collections.reverse(rows);
		return rows;
	}