LintCode解题思路

lintcode-线段树的构造

2016-06-04  本文已影响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;
    }
};
上一篇下一篇

猜你喜欢

热点阅读