16. 最接近的三数之和
为保证权益,题目请参考 16. 最接近的三数之和(From LeetCode).
解决方案1
CPP
C++
#include <iostream>
#include <vector>
#include <set>
using namespace std;
class Solution
{
public:
vector<int> divingBoard(int shorter, int longer, int k)
{
vector<int> res;
if (k)
{
set<int> before_res;
int basic = shorter * k;
int dis = longer - shorter;
before_res.insert(basic);
for (int i = 1; i <= k; ++i)
{
basic += dis;
before_res.insert(basic);
}
for(int x:before_res)
{
res.push_back(x);
}
}
return res;
}
};
int main()
{
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35