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

Method divingBoard

src/com/blankj/easy/_16_11/Solution.java:14–28  ·  view source on GitHub ↗
(int shorter, int longer, int k)

Source from the content-addressed store, hash-verified

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();

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected