2021/05/03
class Solution {
public List<Integer> preorderTraversal(TreeNode root) {
LinkedList<TreeNode> stk = new LinkedList<>();
TreeNode p = root;
List<Integer> res = new ArrayList<>();
while (!stk.isEmpty() || p != null) {
while (p != null) {
res.add(p.val);
stk.push(p);
p = p.left;
}
p = stk.pop();
p = p.right;
}
return res;
}
}