Given an array of positive integers concatenate them to form the largest number possible. For instance, given the array [5, 30, 9], your function should return 9530.
Given an array of positive integers concatenate them to form the largest number possible. For instance, given the array [5, 30, 9], your function should return 9530.
Permalink: http://problemotd.com/problem/largest-number/
Content curated by @MaxBurstein
Comments:
Anonymous - 9 years, 9 months ago
largest_number = lambda x: int(''.join(sorted(map(str, x), reverse=True)))
reply permalink
brix - 9 years, 9 months ago
#include <iostream>
using namespace std;
int main() { int numArray[5]= {5, 30, 9};
cout << numArray[2] << numArray[1] << numArray[0] << endl;
return 0; }
reply permalink
brix - 9 years, 9 months ago
Nope, I now realize I didn't do exactly what the problem asked.
reply permalink