classSolution {publicList<Integer> inorderTraversal(TreeNode root) {List<Integer> result =newLinkedList<>();Stack<TreeNode> stack =newStack<>();while(root!=null||!stack.isEmpty()){//push all the way to the left leafwhile(root!=null){stack.push(root); root=root.left; } root =stack.pop();result.add(root.val); root =root.right; }return result; }}