题解 | #牛奶供应问题#

牛奶供应问题

https://www.nowcoder.com/practice/8c66c9b7deea496193e609b70f39783d

using System;
using System.Collections.Generic;
using System.Linq;


class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param taskDurations int整型一维数组 
     * @param capacity int整型 
     * @return int整型
     */
    public int animalTaskScheduler (List<int> taskDurations, int capacity) {
        // write code here
        List<int> list=new List<int>();
        for(int i=0;i<capacity;i++)
            list.Add(0);
        foreach(int task in taskDurations)
        {
           int index= list.IndexOf(list.Min());
            list[index]+=task;
            
        }
        return list.Max();
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务