Preorder Traversal Time : Space : 123456789101112131415161718192021/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */void helper(TreeNode* node, vector<int>& res) { if(!node) return; res.push_back(node->val); helper(node->left, res); helper(node->right, res);}vector<int> Solution::preorderTraversal(TreeNode* A) { vector<int> res; helper(A,res); return res;}