C++ Easy Solution
\n# Complexity\n- Time complexity : O(N)\n\n- Space complexity : O(1), if we don\u2019t consider the size of the stack for function. Otherwise, O(H) where H is 
\n# Complexity\n- Time complexity : $$O(N)$$\n\n- Space complexity : $$O(1)$$, if we don\u2019t consider the size of the stack for function. Otherwise, $$O(H)$$ where H is the height of the tree. \n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n    vector<int>res;\n    vector<int> preorderTraversal(TreeNode* root) {\n        if(root!=NULL)\n        {\n            res.push_back(root->val);\n            preorderTraversal(root->left);\n            preorderTraversal(root->right); \n        }\n        return res;\n    }\n};\n```
['Tree', 'Binary Tree', 'C++']