MCPcopy Create free account
hub / github.com/Blankj/awesome-java-leetcode / Solution

Class Solution

src/com/blankj/easy/_16_11/Solution.java:13–34  ·  view source on GitHub ↗

author: Blankj blog : http://blankj.com time : 2020/07/08 desc :

Source from the content-addressed store, hash-verified

11 * </pre>
12 */
13public class Solution {
14 public int[] divingBoard(int shorter, int longer, int k) {
15 if (k == 0) {
16 return new int[0];
17 }
18 if (shorter == longer) {
19 return new int[]{shorter * k};
20 }
21 int[] ans = new int[k + 1];
22 int st = k * shorter;// 等差数列的首项
23 int delta = longer - shorter;// 公差
24 for (int i = 0; i <= k; i++) {
25 ans[i] = st + i * delta;
26 }
27 return ans;
28 }
29
30 public static void main(String[] args) {
31 Solution solution = new Solution();
32 System.out.println(Arrays.toString(solution.divingBoard(1, 2, 3)));
33 }
34}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected