[leetcode sort]179. Largest Number
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.
Note: The result may be very large, so you need to return a string instead of an integer.
对一组数字排序,使其组成的数字最大
思路:排序,不过重新定义排序规则,比如字符串x和字符串y,比较x+y和y+x的大小,如果x+y>y+x,则x>y
class Solution:
def largestNumber(self, nums):
nums = [str(n) for n in nums]
nums.sort(cmp=lambda y,x:cmp(x+y,y+x))
return ''.join(nums).lstrip('') or ''
[leetcode sort]179. Largest Number的更多相关文章
- 【Leetcode】179. Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- 【刷题-LeetCode】179 Largest Number
Largest Number Given a list of non negative integers, arrange them such that they form the largest n ...
- leetcode 179. Largest Number 、剑指offer33 把数组排成最小的数
这两个题几乎是一样的,只是leetcode的题是排成最大的数,剑指的题是排成最小的 179. Largest Number a.需要将数组的数转换成字符串,然后再根据大小排序,这里使用to_strin ...
- JavaScript中sort方法的一个坑(leetcode 179. Largest Number)
在做 Largest Number 这道题之前,我对 sort 方法的用法是非常自信的.我很清楚不传比较因子的排序会根据元素字典序(字符串的UNICODE码位点)来排,如果要根据大小排序,需要传入一个 ...
- [LeetCode] 179. Largest Number 最大组合数
Given a list of non negative integers, arrange them such that they form the largest number. Example ...
- leetcode 179. Largest Number 求最大组合数 ---------- java
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- Java for LeetCode 179 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- [LeetCode] 179. Largest Number 解题思路
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- [leetcode]179. Largest Number最大数
Given a list of non negative integers, arrange them such that they form the largest number. Input: [ ...
随机推荐
- 【Codeforces858F】Wizard's Tour [构造]
Wizard's Tour Time Limit: 50 Sec Memory Limit: 512 MB Description Input Output Sample Input 4 5 1 2 ...
- 20、List集合中特有的方法
List里面的特有方法简介 List中除了Collection里面的方法以外,内部还有一些方法,通过这些方法,开发者可以更方便的操作List接口的实现类. package com.monkey1024 ...
- 【译】第六篇 Integration Services:初级工作流管理
本篇文章是Integration Services系列的第六篇,详细内容请参考原文. 简介在前几篇文章中,我们关注使用增量加载方式加载数据.在本篇文章,我们将关注使用优先约束管理SSIS控制流中的工作 ...
- Python的类变量和成员变量、类静态方法和类成员方法
先说明几个相关的术语:attribute.function.method. attribute:类对象的数据成员.我们经常会在Python代码出错时遇到:“AttributeError: 'My_Cl ...
- 让arch阻止某个软件包的升级
我更新了eclipse-java Mars版本的,感觉特别的卡,而且还有好多bug,不知道为什么,因此我去官网下载了luna版本的eclipse的安装包,不知道怎么下载的点击这里,然后安装luna版本 ...
- sru源码--language model
import sys import os import argparse import time import random import math import numpy as np import ...
- sleep允许休眠, delay不允许
在Linux Driver开发中,经常要用到延迟函数:msleep,mdelay/udelay. 虽然msleep和mdelay都有延迟的作用,但他们是有区别的. 1.)对于模块本身 mdelay是忙 ...
- 64_t7
texlive-ulqda-bin-svn13663.0-33.20160520.fc26.2..> 24-May-2017 15:57 33102 texlive-ulqda-doc-svn2 ...
- Fiddler是最强大最好用的Web调试工具
Fiddler是最强大最好用的Web调试工具之一,它能记录所有客户端和服务器的http和https请求,允许你监视,设置断点,甚至修改输入输出数据. 使用Fiddler无论对开发还是测试来说,都有很大 ...
- ASP.net-空白页的问题
protected void Application_Error(object sender, EventArgs e) { ILog log = LogMan ...