C Solution
\n\nint nodeCount(struct TreeNode* root) {\n    if (NULL == root)\n        return 0;\n    \n    return (nodeCount(root->left)+ nodeCount(root->right)) + 1;\n}\n
```\n\nint nodeCount(struct TreeNode* root) {\n    if (NULL == root)\n        return 0;\n    \n    return (nodeCount(root->left)+ nodeCount(root->right)) + 1;\n}\n\nvoid preorder(struct TreeNode* root, int *res, int *size) {\n    if(NULL == root)\n        return;\n    \n    res[(*size)++] = root->val;\n    preorder(root->left, res, size);\n    preorder(root->right, res, size);\n}\n\nint* preorderTraversal(struct TreeNode* root, int* returnSize){\n    int lev = nodeCount(root);\n    \n    int *result =(int*)malloc(sizeof(int)*lev+1);\n    *returnSize = 0;\n\n    preorder(root, result, returnSize);\n    \n    return result;\n}\n```
[]