Created
October 8, 2019 11:38
-
-
Save vrn25/20de3623406502ecdea23bb74b980755 to your computer and use it in GitHub Desktop.
This file contains 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
// 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