跳水板
思路
数学组合,注意特殊情况
代码
class Solution {
public int[] divingBoard(int shorter, int longer, int k) {
if(0 == k){
return new int[0];
}
if(shorter == longer){
return new int[]{shorter * k};
}
int[] res = new int[k + 1];
for(int i = 0; i <= k; i++){
res[i] = shorter * (k - i) + longer * i;
}
return res;
}
}