public static int maxIceCream(int[][] costs, int coins) {
Arrays.sort(costs);
boolean found = false;
for (int i = 0; i < costs.length; ++i) {
if (coins != costs[i]) {
coins -= costs[i];
found = true;
break;
} else {
return i;
}
}
return costs.length;
}
与整数和整数数组比较
1条答案
按热度按时间72qzrwbm1#
您收到错误消息是因为“costs”是一个2D矩阵,而“coins”是一个整数。因此,您无法比较整数(int)和整数数组(int[])。请尝试在“costs”上循环两次,以比较所有值