leetcode-hard-array-179 Largest Number-NO
mycode 写的很复杂,还报错。。。
参考:
class Solution:
# @param {integer[]} nums
# @return {string}
def largestNumber(self, nums):
n = len(nums)
for i in range(n):
for j in range(n-i-1):
temp_1 = str(nums[j])
temp_2 = str(nums[j+1])
if(int(temp_1+temp_2)<int(temp_2+temp_1)):
temp = nums[j]
nums[j] = nums[j+1]
nums[j+1] = temp
output = ''
for i in nums:
output = output + str(i)
return str(int(output))
class Solution(object):
def largestNumber(self, nums):
"""
:type nums: List[int]
:rtype: str
"""
def compare(a,b):
return int(b + a) - int(a + b)
nums = sorted([str(x) for x in nums],cmp = compare)
ans = ''.join(nums).lstrip('') return ans or ''
leetcode-hard-array-179 Largest Number-NO的更多相关文章
- leetcode 179. Largest Number 、剑指offer33 把数组排成最小的数
这两个题几乎是一样的,只是leetcode的题是排成最大的数,剑指的题是排成最小的 179. Largest Number a.需要将数组的数转换成字符串,然后再根据大小排序,这里使用to_strin ...
- [LeetCode] 179. Largest Number 最大组合数
Given a list of non negative integers, arrange them such that they form the largest number. Example ...
- 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. Input: [ ...
- 【Leetcode】179. Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- Java 特定规则排序-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 求最大组合数 ---------- 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 sort]179. Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
随机推荐
- zxx.cms.app 开发中的一些git命令
第一行命令 查看当前项目git的状态 显示是干净的 第二行创建一个 login 分支 并且切换到login 分支 用于login功能模块的开发 第三行 查看当前 所有的 分支 安装less-loade ...
- STM32工程模版
STM32工程模版,看过来 ST库源码去官方下载 创建工程目录 doc:存放说明文档 lib:存放库文件 listing:存放编译产生的中间文件 output:存放生成的文件 project:存放工程 ...
- 19.SSM整合_配置式开发
1.定义实体类Student 2.定义Student表 3.定义index页面 4.定义处理器 5.定义Service 6.定义Dao接口 7.定义Dao的Mapper配置文件 8.定义MyBatis ...
- 【转】Delphi货币类型转中文大写金额
unit TU2.Helper.Currency; interface ): string; ): string; implementation uses System.SysUtils, Syste ...
- Image Processing and Computer Vision_Review:A survey of recent advances in visual feature detection(Author's Accepted Manuscript)——2014.08
翻译 一项关于视觉特征检测的最新进展概述(作者已被接受的手稿) 和A survey of recent advances in visual feature detection——2014.08内容相 ...
- RHEL6进入救援模式
1.救援模式 救援模式作用: 更改root密码: 恢复硬盘.文件系统操作 系统无法启动时,通过救援模式启动 2.放入系统光盘,重启从光盘启动: 4.选择语言,默认English就行 5.保持默 ...
- C# 安装WindowsService时弹出设置服务登录窗口的解决方案
使用SignalR实现消息推送,页面实时刷新,使用WindowsService作为SignalR的宿主,也就是作为一个消息服务器,在使用cmd命令安装的时候弹出设置服务登录的窗口,解决此问题的具体操作 ...
- linux-2.6.38 input子系统(用输入子系统实现按键操作)
一.设备驱动程序 在上一篇随笔中已经分析,linux输入子系统分为设备驱动层.核心层和事件层.要利用linux内核中自带的输入子系统实现一个某个设备的操作,我们一般只需要完成驱动层的程序即可,核心层和 ...
- 实用: 将程序的内容写出到excel中
pom <!-- 读取excel文件 --><dependency> <groupId>org.apache.poi</groupId> <art ...
- js技术javascript 该重视
当下,js大有挤压php java asp.net之类后端语言的趋势,直接js html5 socket与后端python c c++ 等通信 更不用提二维 三维计算展示 方面 医院呼叫 报警 处理 ...