Skip to content

Commit 4c49308

Browse files
authored
Create 179. Largest Number (#588)
2 parents 6065f37 + 98bec4c commit 4c49308

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

179. Largest Number

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
public:
3+
string largestNumber(vector<int>& nums) {
4+
vector<string>ans;
5+
for (auto it : nums)
6+
{
7+
ans.push_back(to_string(it)); // convert in string
8+
}
9+
sort(ans.begin(), ans.end(), [](string a, string b)
10+
{
11+
return a + b > b + a;
12+
});
13+
string s ="";
14+
for (auto it : ans)
15+
{
16+
s= s+ it;
17+
}
18+
while(s.size()>1 && s[0]=='0') // last edge case consider
19+
{
20+
s.erase(s.begin());
21+
}
22+
return s;
23+
}
24+
};

0 commit comments

Comments
 (0)