Second, the fitness program evaluation ( LeetCode 5174- )
2.1 Title Description
2.2 Problem-solving ideas
Very simple a question, a clear understanding of the meaning of problems just fine. As long as k consecutive days can be.
2.3 Code Solving
public class Solution {
public int dietPlanPerformance(int[] calories, int k, int lower, int upper) {
int res = 0;
int len = calories.length;
OK:
for (int i = 0; i < len; i++) {
int sum = 0;
if (i + k > len) {
continue OK;
}
for (int j = 0; j < k; j++) {
sum += calories[i + j];
}
if (sum > upper) {
res++;
}
if (sum < lower) {
res--;
}
}
return res;
}
}