2017.9.8
总感觉自己的方法太暴力。
/**
* Definition of SegmentTreeNode:
* public class SegmentTreeNode {
* public int start, end, max;
* public SegmentTreeNode left, right;
* public SegmentTreeNode(int start, int end, int max) {
* this.start = start;
* this.end = end;
* this.max = max
* this.left = this.right = null;
* }
* }
*/
public class Solution {
/*
* @param root: The root of segment tree.
* @param index: index.
* @param value: value
* @return:
*/
public void modify(SegmentTreeNode root, int index, int value) {
// write your code here
if(root == null){
return;
}
if(index < root.start || index > root.end){
return;
}
if(root.start == root.end && root.end == index){
root.max = value;
}
else{
modify(root.left, index, value);
modify(root.right, index, value);
root.max = Math.max(root.left.max, root.right.max);
}
}
}