Skip to content

Instantly share code, notes, and snippets.

@vrn25
Created October 8, 2019 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vrn25/20de3623406502ecdea23bb74b980755 to your computer and use it in GitHub Desktop.
Save vrn25/20de3623406502ecdea23bb74b980755 to your computer and use it in GitHub Desktop.
// Problem for week 1 codebuddy IEEE: https://www.interviewbit.com/problems/largest-number/
bool comp(string a, string b){
string f1 = a+b;
string f2 = b+a;
return f1>f2?1:0;
}
string Solution::largestNumber(const vector<int> &A) {
if(!accumulate(A.begin(),A.end(),0))
return "0";
vector<string>v;
for(int i=0;i<A.size();i++)
v.push_back(to_string(A[i]));
sort(v.begin(),v.end(),comp);
string ans;
for(int i=0;i<A.size();i++)
ans += v[i];
return ans;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment