Created
September 21, 2019 08:07
-
-
Save surinoel/373344db056c6b9b67624d8d4215e643 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
bool cmp(const string& u, const string& v) { | |
if (u == v) return false; | |
string a = u + v; | |
string b = v + u; | |
if (a > b) return true; | |
else return false; | |
} | |
string solution(vector<int> numbers) { | |
string answer = ""; | |
vector<string> ns; | |
int zerocount = 0; | |
for (int i = 0; i < numbers.size(); i++) { | |
string tmp = to_string(numbers[i]); | |
ns.push_back(tmp); | |
if (tmp.front() == '0' && tmp.back() == '0') { | |
zerocount += 1; | |
} | |
} | |
if (zerocount == numbers.size()) { | |
return "0"; | |
} | |
sort(ns.begin(), ns.end(), cmp); | |
for (int i = 0; i < ns.size(); i++) { | |
answer += ns[i]; | |
} | |
return answer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment