- Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSolution932.java
More file actions
Latest commit
executable file
·56 lines (52 loc) · 1.52 KB
/
Copy pathSolution932.java
File metadata and controls
executable file
·56 lines (52 loc) · 1.52 KB
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
importjava.util.ArrayList;
importjava.util.Arrays;
/**
* Created by slade on 2019/6/24.
*/
publicclassSolution932 {
publicint[] beautifulArray(intN) {
ArrayList<Integer> tmpOdd = newArrayList<>();
ArrayList<Integer> tmpEven = newArrayList<>();
ArrayList<Integer> tmp = newArrayList<>();
ArrayList<Integer> tmp_remove = newArrayList<>();
tmp.addAll(Arrays.asList(2, 1, 4, 3));
if (N == 1) {
int[] res = newint[]{1};
returnres;
}
if (N == 2) {
int[] res = newint[]{1, 2};
returnres;
}
if (N == 3) {
int[] res = newint[]{3, 1, 2};
returnres;
}
while (tmp.size() < N) {
for (intitem : tmp
) {
tmpOdd.add(item * 2 - 1);
tmpEven.add(item * 2);
}
tmp.clear();
tmp.addAll(tmpOdd);
tmp.addAll(tmpEven);
tmpOdd.clear();
tmpEven.clear();
}
for (intitem : tmp) {
if (item <= N) {
tmp_remove.add(item);
}
}
int[] res_out = newint[tmp_remove.size()];
for (intidx = 0; idx < tmp_remove.size(); idx++) {
res_out[idx] = tmp_remove.get(idx);
}
returnres_out;
}
publicstaticvoidmain(String[] args) {
Solution932s = newSolution932();
System.out.println(Arrays.toString(s.beautifulArray(10)));
}
}