Easy C++ Solution with Explaination
AN UPVOTE WOULD BE HIGHLY APPRECIATED !!!\n\nOverload the comments section with doubts and praises if you have.!!!\n\nTime Complexity: O(n)\nSpace Complexity: O
**AN UPVOTE WOULD BE HIGHLY APPRECIATED !!!**\n\n*Overload the comments section with doubts and praises if you have.!!!*\n\nTime Complexity: O(n)\nSpace Complexity: O(n)\n\n```\nclass Solution {\npublic:\n// Declairing global variable *ans* so that we don\'t declare it again and again and affect the SC by some factors\n    vector<int> ans;\n    \n\t// Find the preorder sequence\n    void preorder(TreeNode* root) {\n        if(root==NULL) {\n            return;\n        }\n        ans.push_back(root->val);\n        preorder(root->left);\n        preorder(root->right);        \n    }\n    \n    // Recieve the preorder sequence from *preorder()* and return it\n    vector<int> preorderTraversal(TreeNode* root) {\n   \n        preorder(root);\n        return ans;\n    }\n};\n```
['C', 'C++']