-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path2578.cpp
More file actions
30 lines (29 loc) · 724 Bytes
/
2578.cpp
File metadata and controls
30 lines (29 loc) · 724 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
29
30
class Solution {
public:
int splitNum(int num) {
vector<int> hash(10, 0);
while (num) {
hash[num % 10]++;
num /= 10;
}
int num1 = 0;
int num2 = 0;
bool num1Turn = true;
for (int i = 0; i < 10; ++i) {
int count = hash[i];
for (int j = 0; j < count; ++j) {
if (num1Turn) {
num1 *= 10;
num1 += i;
num1Turn = false;
}
else {
num2 *= 10;
num2 += i;
num1Turn = true;
}
}
}
return num1 + num2;
}
};