✔️ 0ms | explained easy solution | C++
Approach\nIn this question we need to traverse or move through this tree in pre order traversal\n\nFirst the root node, then the next node (left sibling, or lef
# Approach\nIn this question we need to traverse or move through this tree in pre order traversal\n\nFirst the root node, then the next node (left sibling, or left node) and after all the left nodes are exhausted on the left subtree, we go back on e node and check the right node or right sibling. Again when all nodes are done on that level we go back one level and repeat the same process unless we have reached the root back again; and then we start traversing the right sub tree, but here too we first go through the left siblings first and then the right siblings.\n\n```\nclass Solution {\npublic:\n    void traverse(TreeNode* root, vector<int>& v) {\n        if (root==NULL) return;     // if node is null there is nothing more to check\n        v.push_back(root->val);     // We first add the node we\'re visiting to the output vector\n        traverse(root->left, v);    // Now let\'s move through the left siblings\n        traverse(root->right, v);   // After the left siblings are done with, we check for the right siblings as we start going back\n    }\n\npublic:\n    vector<int> preorderTraversal(TreeNode* root) {\n        vector<int> v;\n        traverse(root, v);\n        return v;\n    }\n};\n```\n\n\n*Upvote this solution, as it might have helped you :)*
['C++']