欢迎光临散文网 会员登陆 & 注册

Leetcode1176 Diet Plan Performance

2023-01-02 16:39 作者:您是打尖儿还是住店呢  | 我要投稿

A dieter consumes calories[i] calories on the i-th day. For every consecutive sequence of k days, they look at T, the total calories consumed during that sequence of k days:

If T < lower, they performed poorly on their diet and lose 1 point; If T > upper, they performed well on their diet and gain 1 point; Otherwise, they performed normally and there is no change in points. Return the total number of points the dieter has after all calories.length days.

Note that: The total points could be negative.

Example 1:

Input: calories = [1,2,3,4,5], k = 1, lower = 3, upper = 3 Output: 0 Explaination: calories[0], calories[1] < lower and calories[3], calories[4] > upper, total points = 0.

Example 2:

Input: calories = [3,2], k = 2, lower = 0, upper = 1 Output: 1 Explaination: calories[0] + calories[1] > upper, total points = 1.

Example 3:

Input: calories = [6,5,0,0], k = 2, lower = 1, upper = 5 Output: 0 Explaination: calories[0] + calories[1] > upper, calories[2] + calories[3] < lower, total points = 0.

Constraints:

  1. 1 <= k <= calories.length <= 10^5

  • 0 <= calories[i] <= 20000

  • 0 <= lower <= upper

这次的题目是锁着的,所以只能在GitHub上面找原题,测试案例只有2个了,,所以不知道跑数量级比较大的时候,会不会报错了。

数组也可以循环,只是想用下ArrayList,先遍历,每次根据K,求对应的值,即可跑出来数据的。

Leetcode1176 Diet Plan Performance的评论 (共 条)

分享到微博请遵守国家法律