1 2 3 4 5 6 7 8 9 10 11 12 13 14
| vector<int> preorderTraversal(TreeNode* root) { vector<int> chain = {}; preorderTraversalRecur(root, &chain); return chain; }
void preorderTraversalRecur(TreeNode* root, vector<int>* chain) { if (!root) { return; } chain->push_back(root->val); preorderTraversalRecur(root->left, chain); preorderTraversalRecur(root->right, chain); }
|