1 /**
2 * Definition of TreeNode:
3 * class TreeNode {
4 * public:
5 * int val;
6 * TreeNode *left, *right;
7 * TreeNode(int val) {
8 * this->val = val;
9 * this->left = this->right = NULL;
10 * }
11 * }
12 */
13
14 class Solution {
15 public:
16 vector<int> s;
17 /**
18 * @param root: The root of binary tree.
19 * @return: Preorder in vector which contains node values.
20 */
21
22 vector<int> preorderTraversal(TreeNode *root) {
23 // write your code here
24 if(root==NULL)
25 return s;
26 if(root!=NULL)
27 {
28 s.push_back(root->val);
29 preorderTraversal(root->left);
30 preorderTraversal(root->right);
31 return s;
32 }
33 }
34 };