-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path42.cpp
67 lines (54 loc) · 1.19 KB
/
42.cpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Solution
{
public:
int dp(int start, int end, vector<int> &vec)
{
int ret = 0;
if (start == end)
{
return 0;
}
else if (start > end)
{
return 0;
}
else
{
if (end - start < 2)
{
return 0;
}
else
{
int level = min(vec[start], vec[end]);
for (int i = start + 1; i < end; i++)
{
ret += (level - vec[i]);
}
}
}
return ret;
}
int trap(vector<int> &height)
{
vector<int> indexes;
for (auto i = 0; i < height.size(); i++)
{
indexes.push_back(i);
}
stable_sort(indexes.begin(), indexes.end(), [&height](int a, int b)
{ return height[a] > height[b]; });
return 0;
}
};
int main(int argc, char const *argv[])
{
auto s = new Solution();
vector<int> a = {0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1};
s->trap(a);
return 0;
}