题目链接
跳水板
题目描述
注意点
- 返回的长度需要从小到大排列
 - 必须正好使用k块木板
 - 0 < shorter <= longer
 - 0 <= k <= 100000
 
解答思路
- 用k块两种不同的木板,组合数为k + 1,最小的组合为全部使用shorter,每多一块longer,减少一块shorter,组合的长度增加longer - shorter
 
代码
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];
        int min = shorter * k;
        int diff = longer - shorter;
        for (int i = 0; i <= k; i++) {
            res[i] = min + diff * i;
        }
        return res;
    }
}
 
关键点
- k = 0时不能使用模板,没有组合
 - 当shorter = longer时只有一种组合,不管选几块shorter和longer最终的组合长度都是相同的
 


















![[C++]——同步异步日志系统(4)](https://i-blog.csdnimg.cn/direct/0017e03e17a34dfe993636be6d6327c3.png)

