成人无码视频,亚洲精品久久久久av无码,午夜精品久久久久久毛片,亚洲 中文字幕 日韩 无码

資訊專欄INFORMATION COLUMN

[LeetCode] 621. Task Scheduler

Hujiawei / 2632人閱讀

Problem

Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks.Tasks could be done without original order. Each task could be done in one interval. For each interval, CPU could finish one task or just be idle.

However, there is a non-negative cooling interval n that means between two same tasks, there must be at least n intervals that CPU are doing different tasks or just be idle.

You need to return the least number of intervals the CPU will take to finish all the given tasks.

Example:
Input: tasks = ["A","A","A","B","B","B"], n = 2
Output: 8
Explanation: A -> B -> idle -> A -> B -> idle -> A -> B.

Note:

The number of tasks is in the range [1, 10000].
The integer n is in the range [0, 100].

Solution Using sort
class Solution {
    public int leastInterval(char[] tasks, int n) {
        int[] records = new int[26];
        for (char ch: tasks) {
            records[ch-"A"]++;
        }
        Arrays.sort(records);
        int i = 25;
        while (i >= 0 && records[i] == records[25]) i--;
        return Math.max(tasks.length, (records[25]-1)*(n+1) + (25-i));
    }
}
Using counter
class Solution {
    public int leastInterval(char[] tasks, int n) {
        int[] records = new int[26];
        int max = 0, maxCount = 0;
        for (char ch: tasks) {
            records[ch-"A"]++;
            if (records[ch-"A"] == max) maxCount++;
            else if (records[ch-"A"] > max) {
                maxCount = 1;
                max = records[ch-"A"];
            }
        }
        
        int parts = (n+1) * (max-1);
        int part = maxCount;
        return Math.max(tasks.length, parts+part);
    }
}

文章版權歸作者所有,未經(jīng)允許請勿轉載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉載請注明本文地址:http://m.hztianpu.com/yun/71842.html

相關文章

  • 【JAVA新生】拿協(xié)程開始寫個異步io應用

    摘要:接下來,就看怎么用協(xié)程來實現(xiàn)異步了。直接拿的原始寫代碼會死人的。引入?yún)f(xié)程就是為了把上下連續(xù)的業(yè)務邏輯放在一個協(xié)程里,把與業(yè)務關系不大的的處理部分放到框架的里。第三部分是放棄掉執(zhí)行權。這樣一個只能接收打印一行的異步應用就寫好了。 前面已經(jīng)準備好了greenlet對應的Java版本了,一個刪減后的kilim(http://segmentfault.com/blog/taowen/11900...

    singerye 評論0 收藏0
  • 【JAVA新生】echo server的第n種寫法

    摘要:基本上所有的網(wǎng)絡應用都會示范一個的寫法。除了這些操作的主體是而不是,操作的是,而不是。以為例其過程是這樣的這段代碼就是創(chuàng)建一個,并注冊一個,并把附著到上。關鍵之一顯然是利用了協(xié)程的和,把回調轉換成順序的邏輯執(zhí)行。 基本上所有的網(wǎng)絡應用都會示范一個tcp的echo寫法。前面我們已經(jīng)看到了如何使用協(xié)程和異步io來做tcp服務器的第一步,accept。下面是一個完整的echo server的...

    Luosunce 評論0 收藏0
  • 爬蟲框架WebMagic源碼分析之Scheduler

    摘要:包主要實現(xiàn)類,這是一個抽象類,實現(xiàn)了通用的模板方法,并在方法內部判斷錯誤重試去重處理等。重置重復檢查就是清空,獲取請求總數(shù)也就是獲取的。至于請求總數(shù)統(tǒng)計,就是返回中維護的的大小。 Scheduler是Webmagic中的url調度器,負責從Spider處理收集(push)需要抓取的url(Page的targetRequests)、并poll出將要被處理的url給Spider,同時還負責...

    TIGERB 評論0 收藏0
  • 阿里云大數(shù)據(jù)MaxCompute計算資源分布以及LogView分析優(yōu)化

    摘要:還可以看到任務運行的開始時間,結束時間,運行時間,點擊就可以看到這個任務執(zhí)行詳情,包括有向無環(huán)圖,和或節(jié)點具體的運行記錄。 摘要: MaxCompute(原ODPS)的概念 海量數(shù)據(jù)處理平臺,服務于批量結構化數(shù)據(jù)的存儲和計算,提供海量數(shù)據(jù)倉庫的解決方案以及針對大數(shù)據(jù)的分析建模服務.(官方文檔有這里就不多做介紹了)官方文檔鏈接 優(yōu)勢 用戶不必關心分布式計算細節(jié),從而達到分析大數(shù)據(jù)的目的。...

    raise_yang 評論0 收藏0

發(fā)表評論

0條評論

閱讀需要支付1元查看
<