lintcode-线段树的修改-203

/**
 * Definition of SegmentTreeNode:
 * class SegmentTreeNode {
 * public:
 *     int start, end, max;
 *     SegmentTreeNode *left, *right;
 *     SegmentTreeNode(int start, int end, int max) {
 *         this->start = start;
 *         this->end = end;
 *         this->max = max;
 *         this->left = this->right = NULL;
 *     }
 * }
 */
class Solution {
public:
    
    void modify(SegmentTreeNode *root, int index, int value) {
        if(!root)
            return ;
            
        
        if(root->start==root->end){
            if(root->start==index)
                root->max=value;
            return ;
        }
        
        modify(root->left,index,value);
        modify(root->right,index,value);
        
        root->max=max(root->left->max,root->right->max);
    }
};

你可能感兴趣的:(lintcode-线段树的修改-203)