leetcode-面试题16.11跳水板

原始思路

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution {
public int[] divingBoard(int shorter, int longer, int k) {
if(k == 0){
return new int[0];
}

List<Integer> result = new ArrayList<>();
HashSet<Integer> set = new HashSet<>();
for(int i = 0; i <= k; i++){
int num = shorter*i+longer*(k - i);
if(!set.contains(num)){
result.add(num);
set.add(num);
}
}

Collections.sort(result);
int[] ans = new int[result.size()];
for (int i = 0; i <result.size() ; i++) {
ans[i] = result.get(i);
}
return ans;
}
}