YSMull
<-- algorithm



原题链接
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;
    }
}