📌  相关文章
📜  在线从 python 转换为 javascript - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:58.885000             🧑  作者: Mango

代码示例4
def choose_best_sum(t, k, ls):
    most = 0

    for i in range(len(ls)-1):
        addN = 0
        if i +k > len(ls) - 1:
            break
        for j in range(i,i+k-1):
            addN += ls[j]
        for p in range(i+k-1,len(ls)-1):
            addN += ls[p]
            if addN > most and addN <= t:
                most = addN
                addN -= ls[p]
            else:
                addN -= ls[p]
    if most == 0:
        return None
    return most