forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1054.cpp
More file actions
28 lines (28 loc) · 680 Bytes
/
1054.cpp
File metadata and controls
28 lines (28 loc) · 680 Bytes
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
static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
class Solution
{
public:
vector<int> rearrangeBarcodes(vector<int>& b)
{
short m[10001] = {};
short max_cnt = 0, max_n = 0, pos = 0;
for (int n : b)
{
if (max_cnt < ++m[n])
{
max_cnt = m[n];
max_n = n;
}
}
for (int i = 0; i <= 10000; ++i)
{
int n = i == 0 ? max_n : i;
while (m[n]-- > 0)
{
b[pos] = n;
pos = pos + 2 < b.size() ? pos + 2 : 1;
}
}
return b;
}
};