Basic C++ solution


#1
void PreOrder(TreeNode* root, vector<int>& res)
{
    if (!root)
        return;
    res.emplace_back(root->val);
    PreOrder(root->left, res);
    PreOrder(root->right, res);
}
vector<int> Solution::preorderTraversal(TreeNode* A) {
    vector<int> res;
    PreOrder(A, res);
    return res;
}