栏目分类:
子分类:
返回
终身学习网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
终身学习网 > IT > 软件开发 > 后端开发 > Java

力扣:732. 我的日程安排表 III

Java 更新时间:发布时间: 百科书网 趣学号

import org.omg.PortableInterceptor.INACTIVE;

import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;


public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();

    }


}

class MyCalendarThree {
    Map map;
    public MyCalendarThree() {
        map = new TreeMap<>();
    }

    public int book(int start, int end) {
        int ans = 0;
        int maxBook = 0;
        map.put(start, map.getOrDefault(start, 0) + 1);
        map.put(end, map.getOrDefault(end, 0) - 1);
        for (Map.Entry integerIntegerEntry : map.entrySet()) {
            Integer value = integerIntegerEntry.getValue();
            maxBook += value;
            ans = Math.max(maxBook, ans);
        }
        return ans;
    }
}

class MyCalendarThree2 {
    Map tree;
    Map lazy;
    public MyCalendarThree2() {
        tree = new HashMap(16);
        lazy = new HashMap(16);
    }

    public int book(int start, int end) {

        return tree.getOrDefault(1, 0);
    }

    public void update(int start, int end, int l, int r, int idx) {
        // 退出条件
        if (r < start || l > end ){
            return;
        }

        // 初始化
        if (start <= 1 && r <= end){
            tree.put(idx, tree.getOrDefault(idx, 0) + 1);
            lazy.put(idx, lazy.getOrDefault(idx, 0) + 1);
        }else {
            int mid = (l + r) >> 1;
            update(start, end, l, mid, idx * 2);
            update(start, end, mid + 1, r, idx * 2 + 1);
            tree.put(idx, lazy.getOrDefault(idx, 0) + Math.max(tree.getOrDefault(idx * 2
            , 0), tree.getOrDefault(idx * 2 + 1, 0)));
        }

    }
}

转载请注明:文章转载自 www.051e.com
本文地址:http://www.051e.com/it/956825.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 ©2023-2025 051e.com

ICP备案号:京ICP备12030808号