LeetCode OJ 106. Construct Binary Tree from Inorder and Postorder Traversal

Given inorder and postorder traversal of a tree, construct the binary tree.

Note:
You may assume that duplicates do not exist in the tree.

Subscribe to see which companies asked this question

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
struct TreeNode* buildTree(int* inorder, int inorderSize, int* postorder, int postorderSize) {
    int i;
    struct TreeNode *Node;

     >= inorderSize){
        return NULL;
    }
    ; i < inorderSize; i++){
        ]){
            break;
        }
    }
    Node = (struct TreeNode*)malloc(sizeof(struct TreeNode));
    Node->val = postorder[postorderSize - ];
    Node->left = buildTree(inorder, i, postorder, i);
    Node->right = buildTree(inorder + i + , inorderSize - i - , postorder + i, postorderSize - i - );
    return Node;
}
上一篇:systemd服务详解-技术流ken


下一篇:Segments--poj3304(判断直线与线段之间的关系)