https://leetcode.com/problems/largest-number/#/description
Given a list of non negative integers, arrange them such that they form the largest number.
For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.
For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.
1. A naive approach would be put 9 in front of 5, 4, 3. but that would be way too complex for the case when we have 5656 and 56. The right approach is to compare numbers like that. Let’s say we have [3, 34]. We combine them to 343 and 334. 343 is larger than 334 so our list will be sorted to [34, 3]
2. define your own comparator, 1 if a > b, -1 if a < b 3. Syntax for using customized comparator in sorted() sorted(list, cmp = self.methodName)
2. define your own comparator, 1 if a > b, -1 if a < b 3. Syntax for using customized comparator in sorted() sorted(list, cmp = self.methodName)
No comments:
Post a Comment