203

来源:互联网 发布:mac端口号查询 编辑:程序博客网 时间:2024/06/06 02:48

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 hereif(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);}    }}