Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def myfun(a,b):
- if a+b<b+a:
- return -1
- elif a+b>b+a:
- return 1
- else:
- return 0
- class Solution:
- def largestNumber(self, nums: List[int]) -> str:
- nums=[str(i) for i in nums]
- nums.sort(reverse=True, key=cmp_to_key(myfun))
- ans=""
- for i in nums:
- if ans=="" and i=='0': #this is needed to remove the initial zeros
- continue
- ans+=i
- return ans if ans!="" else '0' #this is needed if input arr=['0','0']
Advertisement
Add Comment
Please, Sign In to add comment