# Largest Number

• Click here to see the full article post

• I didnot understand the code ,could anyone help me ?

• Which part? look up the comparator interface on javatpoint if you didnt understand the Java solution

• One of the most challenging problem solved as a novice by myself! great feat for me, but looking editorial made me sad as i wouldn't took advantage of inbuilt java functionalities!

• Hello all,

what about my solution ?
Can someone confirm this is a O(N) Time complexity solution ?

``````/*
* Time O(N) complexity
*
*/

struct Comparator {
bool operator()(const string& lhs, const string& rhs) {
return lhs + rhs > rhs + lhs;
}
};

class Solution {
public:
string largestNumber(vector<int>& nums) {
string result;

vector<string> s;

// Edge case
int ec =  *(max_element(nums.begin(), nums.end()));
if (ec == *(min_element(nums.begin(), nums.end())) && ec == 0)
return to_string(ec);

for (vector<int>::iterator it = nums.begin(); it != nums.end(); ++it) {
s.push_back(to_string(*it));
}

sort(s.begin(), s.end(), Comparator());

for (vector<string>::iterator it = s.begin(); it != s.end(); ++it) {
result += *it;
}

return result;
}
};
``````

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.