public static List<Integer> solution(TreeNode root) {
        List<Integer> list = new ArrayList<Integer>();
        if (root == null) {
            return list;
        }

        Stack<TreeNode> stack = new Stack<TreeNode>();
        stack.push(root);
        while (!stack.isEmpty()) {
            TreeNode current = stack.peek();
            if (current.left != null) {
                System.out.println("--->" + current.val);
                stack.push(current.left);
                TreeNode tmp = current.left;
                current.left = null;
                current = tmp;
            }

            if (current.left == null && current.right != null) {
                stack.push(current.right);
                TreeNode tmp = current.right;
                current.right = null;
                current = tmp;
            }

            if (current.left == null && current.right == null) {
                list.add(stack.pop().val);
                //System.out.println(current.val);
            }
        }
        return list;
    }