3 Different Solutions
Recursive method with List as returning value:\n\n    \tpublic List preorderTraversal(TreeNode root) {\n    \t\tList pre = new LinkedList();\n    \t\tif(root==n
Recursive method with List as returning value:\n\n    \tpublic List<Integer> preorderTraversal(TreeNode root) {\n    \t\tList<Integer> pre = new LinkedList<Integer>();\n    \t\tif(root==null) return pre;\n    \t\tpre.add(root.val);\n    \t\tpre.addAll(preorderTraversal(root.left));\n    \t\tpre.addAll(preorderTraversal(root.right));\n    \t\treturn pre;\n    \t}\n\nRecursive method with Helper method to have a List as paramater, so we can modify the parameter and don't have to instantiate a new List at each recursive call:\n\n    \tpublic List<Integer> preorderTraversal(TreeNode root) {\n    \t\tList<Integer> pre = new LinkedList<Integer>();\n    \t\tpreHelper(root,pre);\n    \t\treturn pre;\n    \t}\n    \tpublic void preHelper(TreeNode root, List<Integer> pre) {\n    \t\tif(root==null) return;\n    \t\tpre.add(root.val);\n    \t\tpreHelper(root.left,pre);\n    \t\tpreHelper(root.right,pre);\n    \t}\n\nIterative method with Stack:\n\n    \tpublic List<Integer> preorderIt(TreeNode root) {\n    \t\tList<Integer> pre = new LinkedList<Integer>();\n    \t\tif(root==null) return pre;\n    \t\tStack<TreeNode> tovisit = new Stack<TreeNode>();\n    \t\ttovisit.push(root);\n    \t\twhile(!tovisit.empty()) {\n    \t\t\tTreeNode visiting = tovisit.pop();\n    \t\t\tpre.add(visiting.val);\n    \t\t\tif(visiting.right!=null) tovisit.push(visiting.right);\n    \t\t\tif(visiting.left!=null) tovisit.push(visiting.left);\n    \t\t}\n    \t\treturn pre;\n    \t}
['Recursion', 'Iterator', 'Java']