bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 179. Largest Number

179. Largest Number

Leetcode Solutions

Sorting via Custom Comparator

  1. Convert all integers in the nums array to strings.
  2. Define a custom comparator that compares two strings a and b by comparing a + b and b + a.
  3. Sort the array of strings using the custom comparator.
  4. Concatenate all the strings in the sorted array to form the largest number.
  5. If the first string in the sorted array is '0', return '0' as the result.
  6. Otherwise, return the concatenated string as the result.
UML Thumbnail

Brute Force with Permutations

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...