forked from illuz/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAC_sort_nlogn.cpp
47 lines (38 loc) · 853 Bytes
/
AC_sort_nlogn.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
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: AC_sort_nlogn.cpp
* Create Date: 2015-02-26 10:13:18
* Descripton: sort + cmp
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 0;
class Solution {
private:
static bool cmp(string a, string b) {
return (a + b) > (b + a);
}
public:
string largestNumber(vector<int> &num) {
vector<string> str;
for (auto &i : num)
str.push_back(to_string(i));
sort(str.begin(), str.end(), cmp);
string ans;
if (str[0] == "0")
return "0";
for (auto &i : str)
ans += i;
return ans;
}
};
int main() {
int n, t;
Solution s;
cin >> n;
vector<int> num(n);
for (auto &i : num)
cin >> i;
cout << s.largestNumber(num) << endl;
return 0;
}