题目来源:https://leetcode-cn.com/problems/diving-board-lcci/

LeetCode日记  面试题16.11跳水板_i++


比较简单,就懒得说思路了,用数学

class Solution {
public int[] divingBoard(int shorter, int longer, int k) {
if(k<=0){
return new int [0];
}
if(shorter==longer){
return new int[]{shorter * k};
}

int[] res = new int[k+1];
res[0] = shorter*k;
for(int i = 1;i <= k;i++){
//res[i] = (k-i)*shorter+i*longer;
res[i] = res[i-1] + longer - shorter;
}

return res;

}
}