Skip to content

Latest commit

 

History

History
59 lines (43 loc) · 1.52 KB

0179-largest-number.adoc

File metadata and controls

59 lines (43 loc) · 1.52 KB

179. Largest Number

{leetcode}/problems/largest-number/[LeetCode - Largest Number^]

Given a list of non negative integers, arrange them such that they form the largest number.

Example 1:

Input: [10,2]
Output: "`210"`

Example 2:

Input: [3,30,34,5,9]
Output: "`9534330"`

Note: The result may be very large, so you need to return a string instead of an integer.

思路分析

这道题很容易想到需要根据数字的字符串大小进行倒序排列(目的是将首个数字比较大的数字排在前面)。但如果直接比较数字对应的字符串大小,则在某些场景下不能满足要求。最简单省事的方式就是直接将排序的两个字符串相加(左右,右左)进行比较就可以了。

{image_attr}
一刷
link:{sourcedir}/_0179_LargestNumber.java[role=include]
二刷
link:{sourcedir}/_0179_LargestNumber_2.java[role=include]