0
Leetcode Problem 179. Largest Number
179. Largest Number
AI Mock Interview
Leetcode Solutions
Sorting via Custom Comparator
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Convert all integers in the
nums
array to strings.
Define a custom comparator that compares two strings
a
and
b
by comparing
a + b
and
b + a
.
Sort the array of strings using the custom comparator.
Concatenate all the strings in the sorted array to form the largest number.
If the first string in the sorted array is '0', return '0' as the result.
Otherwise, return the concatenated string as the result.
Brute Force with Permutations
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...