Easy to read JAVA solutions for both iterative and recursive (<300ms)
Recursive:\n\n    public class Solution {\n        List traversal = new ArrayList<>();\n        public List preorderTraversal(TreeNode root) {\n            if(r
Recursive:\n\n    public class Solution {\n        List<Integer> traversal = new ArrayList<>();\n        public List<Integer> preorderTraversal(TreeNode root) {\n            if(root!=null){helper(root);}\n            return traversal;\n        }\n        \n        void helper (TreeNode root){\n            traversal.add(root.val);\n            if(root.left!=null){helper(root.left);}\n            if(root.right!=null){helper(root.right);}\n            \n        }\n    }\n\nIterative: Use Stack\n\n    public class Solution {\n        public List<Integer> preorderTraversal(TreeNode root) {\n            Stack<TreeNode> stack = new Stack<>();\n            List<Integer> traversal = new ArrayList<>();\n            if(root!=null){\n                stack.push(root);\n                while(!stack.isEmpty()){\n                    TreeNode curr = stack.pop();\n                    traversal.add(curr.val);\n                    if(curr.right!=null){ stack.push(curr.right); }\n                    if(curr.left!=null){ stack.push(curr.left);  }\n                }\n            }\n            return traversal;\n        }\n    }
[]