lintcode-线段树的修改-203

来源:互联网 发布:网络炒作团队怎么收费 编辑:程序博客网 时间:2024/06/15 20:13
/** * 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);    }};

0 0
原创粉丝点击