美文网首页LintCode解题思路
lintcode-线段树的构造

lintcode-线段树的构造

作者: 鬼谷神奇 | 来源:发表于2016-06-04 23:42 被阅读17次
    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;
        }
    };
    

    相关文章

      网友评论

        本文标题:lintcode-线段树的构造

        本文链接:https://www.haomeiwen.com/subject/ibaldttx.html