Java | O(n) | 0 MS
Intuition\n    step 1---> add the root element in list\n    step 2--->add the left element in list\n    step 3--->add the right element in list\n\n# Approach\n 
# Intuition\n    step 1---> add the root element in list\n    step 2--->add the left element in list\n    step 3--->add the right element in list\n\n# Approach\n    Using Recursion\n\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n\n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     int val;\n *     TreeNode left;\n *     TreeNode right;\n *     TreeNode() {}\n *     TreeNode(int val) { this.val = val; }\n *     TreeNode(int val, TreeNode left, TreeNode right) {\n *         this.val = val;\n *         this.left = left;\n *         this.right = right;\n *     }\n * }\n */\nclass Solution {\n    public List<Integer> preorderTraversal(TreeNode root) {\n        List<Integer> list =new ArrayList<>();\n        if(root!=null){\n        //root-->left-->right====>pre-order traversal\n        list.add(root.val);\n        list.addAll(preorderTraversal(root.left));\n        list.addAll(preorderTraversal(root.right));\n        return list;\n        }\n    //   If the Root is NULL ,then return the list\n        return list;\n        \n    }\n}\n```\n![upvote.jpeg](https://assets.leetcode.com/users/images/27555805-c730-4eb8-9b0c-9ebda36f3080_1673225293.3940446.jpeg)\n\n
['Java']