Easy Approach using C
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     struct TreeNode *left;\n *     struct TreeNode *right;\n * };\n */\n\nint* preorderTraversal(struct TreeNode* root, int* returnSize) {\n    if (root == NULL) {\n        *returnSize = 0;\n        return NULL;\n    }\n    struct TreeNode** stack = (struct TreeNode**)malloc(sizeof(struct TreeNode*));\n    int stackSize = 0;\n    int capacity = 1;\n    int* result = (int*)malloc(sizeof(int));\n    int resultSize = 0;\n    while (stackSize > 0 || root != NULL) {\n        while (root != NULL) {\n            result = (int*)realloc(result, (resultSize + 1) * sizeof(int));\n            result[resultSize++] = root->val;\n            if (root->right != NULL) {\n                if (stackSize >= capacity) {\n                    capacity *= 2;\n                    stack = (struct TreeNode**)realloc(stack, capacity * sizeof(struct TreeNode*));\n                }\n                stack[stackSize++] = root->right;\n            }\n            root = root->left;\n        }\n        if (stackSize > 0) {\n            root = stack[--stackSize];\n        }\n    }\n    free(stack);\n    *returnSize = resultSize;\n    return result;\n}\n\n```
['C']