leetcode 94. Binary Tree Inorder Traversal

Orignal question can be found here.

My solution is as follows:

int* inorderTraversal(struct TreeNode* root, int* returnSize)
        int* result=(int*)malloc(sizeof(int)*512);
        if(root == NULL)
                return result;
        inorderTraversalCore(root, result, returnSize);
        return result;

void inorderTraversalCore(struct TreeNode* root, int* array, int* returnSize)
        if(root->left != NULL)
                      inorderTraversalCore(root->left, array, returnSize);
        array[*returnSize] = root->val;
        if(root->right != NULL)
                       inorderTraversalCore(root->right, array, returnSize);

Leave a Reply

Your email address will not be published. Required fields are marked *