[LeetCode] 1744. 你能在你最喜欢的那天吃到你最喜欢的糖果吗?
都儿童节了,为什么要折磨一个几百个月大的孩子?
把题意读懂挺难的。不过读懂后基本也就知道怎么做了。恶心的是int类型可能会越界,要用long类型(很难想到)。这题不好
[1744. 你能在你最喜欢的那天吃到你最喜欢的糖果吗?](https://leetcode-cn.com/problems/can-you-eat-your-favorite-candy-on-your-favorite-day/) ``` class Solution { public boolean[] canEat(int[] candiesCount, int[][] queries) { int n = candiesCount.length; long[] sum = new long[n]; sum[0] = candiesCount[0]; for (int i=1;i int m = queries.length;
boolean[] ans = new boolean[m];
for (int i = 0;i<m;i++) {
int favoriteType = queries[i][0];
int favoriteDay = queries[i][1];
int dailyCap = queries[i][2];
long x1 = favoriteDay + 1;
long y1 = (long) (favoriteDay + 1) * dailyCap;
long x2 = favoriteType == 0 ? 1 : sum[favoriteType - 1] + 1;
long y2 = sum[favoriteType];
ans[i] = !(x1 > y2 || y1 < x2);
}
return ans;
}
}