-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path932.cpp
48 lines (37 loc) · 883 Bytes
/
932.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
class Solution {
public:
//传进来的都要是1~n的数字模式
void part(vector<int>& v, int start, int end)
{
int len = end - start + 1, mid;
if(len == 1)
{
v[start] = 1;
return;
}
if(len % 2 == 0)
{
mid = start + len/2 - 1;
}
else
{
mid = start + len/2;
}
part(v, start, mid);
for(int i = start; i <= mid; ++i)
{
v[i] = 2*v[i] - 1;
}
part(v, mid+1, end);
for(int i = mid+1; i <= end; ++i)
{
v[i] = 2*v[i];
}
}
vector<int> beautifulArray(int N) {
vector<int> v;
v.resize(N);
part(v, 0, N-1);
return v;
}
};