-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLargestNumber.cpp
More file actions
51 lines (42 loc) · 1.1 KB
/
LargestNumber.cpp
File metadata and controls
51 lines (42 loc) · 1.1 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
/* Problem Description:
https://leetcode.com/problems/largest-number/description/
*/
#include <iostream>
#include<vector>
#include <string>
// #include <bits/stdc++.h>
using namespace std;
class Solution {
public:
string largestNumber(vector<int>& nums) {
if (nums.size() == 1 && nums[0] == 0)
return "0";
vector<string> str_nums;
for (auto x : nums) {
str_nums.push_back(to_string(x));
}
sort(str_nums.begin(), str_nums.end(),
[](const string& a, const string& b) -> bool {
if ((a + b) > (b + a)) {
return false;
}
else
return true;
});
string res;
for (int i = (int)str_nums.size()-1; i >= 0; --i) {
res += str_nums[i];
}
cout << "here" << endl;
return res;
}
};
int main(int argc, char const *argv[])
{
int a[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
vector<int> vec(a, a + sizeof(a) / sizeof(a[0]));
Solution sol;
string res = sol.largestNumber(vec);
cout << res << endl;
return 0;
}