Java recursive and iterative solutions.
    \n    // recursively\n    public List<Integer> preorderTraversal1(TreeNode root) {\n        List<Integer> ret = new ArrayList<>();\n        dfs(root, ret);\
        \n    // recursively\n    public List<Integer> preorderTraversal1(TreeNode root) {\n        List<Integer> ret = new ArrayList<>();\n        dfs(root, ret);\n        return ret;\n    }\n    \n    private void dfs(TreeNode root, List<Integer> ret) {\n        if (root != null) {\n            ret.add(root.val);\n            dfs(root.left, ret);\n            dfs(root.right, ret);\n        }\n    }\n    \n    // iteratively\n    public List<Integer> preorderTraversal(TreeNode root) {\n        List<Integer> ret = new ArrayList<>();\n        Stack<TreeNode> stack = new Stack<>();\n        stack.push(root);\n        while (!stack.isEmpty()) {\n            TreeNode node = stack.pop();\n            if (node != null) {\n                ret.add(node.val);\n                stack.push(node.right);\n                stack.push(node.left);\n            }\n        }\n        return ret;\n    }
['Recursion', 'Iterator', 'Java']