lintcode-线段树的构造

class Solution {
public:
    /**
     *@param start, end: Denote an segment / interval
     *@return: The root of Segment Tree
     */
    SegmentTreeNode * build(int start, int end) {
        // write your code here
        if(start > end) {
            return NULL;
        }
        
        SegmentTreeNode * root = new SegmentTreeNode(start, end);
        
        if(start < end) {
            root->left = build(start, (start+end)/2);
            root->right = build((start+end)/2+1, end);
        }
        
        return root;
    }
};
    原文作者:鬼谷神奇
    原文地址: https://www.jianshu.com/p/20ae4ff0c68b
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞