LeetCode:94 二叉树的中序遍历
class Solution { public List<Integer> inorderTraversal(TreeNode root) { Deque<TreeNode> stack = new LinkedList<>(); TreeNode t = root; List<Integer> res = new LinkedList<>(); while(t!=null||!stack.isEmpty()){ if(t!=null){ stack.push(t); t = t.left; } else{ t = stack.pop(); res.add(t.val); t = t.right; } } return res; } }