lintcode segment-tree-modify 线段树的修改
来源:互联网 发布:网站美工要学什么 编辑:程序博客网 时间:2024/06/11 04:12
问题描述
lintcode
笔记
比较左孩子的end
与index
,如果index<=root->left->end
说明index
在左子树,那就递归修改左子树,否则递归修改右子树。最后把root
的max
值更新。
代码
/** * 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: /** *@param root, index, value: The root of segment tree and *@ change the node's value with [index, index] to the new given value *@return: void */ void modify(SegmentTreeNode *root, int index, int value) { // write your code here if (root == NULL) return; if (root->start==root->end) { root->max = value; return; } if (index <= root->left->end) modify(root->left, index, value); else modify(root->right, index, value); root->max = max(root->left->max, root->right->max); }};
0 0
- lintcode segment-tree-modify 线段树的修改
- Lintcode - Segment Tree Modify
- 203.Segment Tree Modify-线段树的修改(中等题)
- [LintCode]Segment Tree Query 线段树的查询
- lintcode segment-tree-build 线段树的构造
- lintcode segment-tree-query 线段树的查询
- [LintCode]Segment Tree Build 构造线段树
- 线段树(segment tree)
- 线段树(segment tree)
- 线段树(segment tree)
- 线段树(segment tree)
- 线段树(segment tree)
- 线段树(segment tree)
- segment tree(线段树)
- #203 Segment Tree Modify
- Segment Tree Modify
- LintCode:线段树的修改
- 线段树的修改-LintCode
- C# 通过Thrift 1 操作 HBase
- 【Android】【完善】【凯子哥带你夯实应用层】滚来滚去,滚来滚去...Scroller相关类使用大揭秘!!!
- ffmpeg 捕获屏幕和采集声卡、摄像头、麦克风声音
- Spark OOM:java heap space,OOM:GC overhead limit exceeded解决方法
- VR入门
- lintcode segment-tree-modify 线段树的修改
- 全双工实现服务器与客户端的通信
- android studio文档教程
- 页面跳转(无结果返回值)(内部监听类事件)
- 面试题46:求1+2+...+n
- 学习之前
- POJ 1328 Radar Installation(预处理贪心)
- c++学习笔记(十):C++类和对象
- Eclipse插件的两种安装方式