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的更多相关文章

  1. leetcode 179. Largest Number 、剑指offer33 把数组排成最小的数

    这两个题几乎是一样的,只是leetcode的题是排成最大的数,剑指的题是排成最小的 179. Largest Number a.需要将数组的数转换成字符串,然后再根据大小排序,这里使用to_strin ...

  2. [LeetCode] 179. Largest Number 最大组合数

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

  3. JavaScript中sort方法的一个坑(leetcode 179. Largest Number)

    在做 Largest Number 这道题之前,我对 sort 方法的用法是非常自信的.我很清楚不传比较因子的排序会根据元素字典序(字符串的UNICODE码位点)来排,如果要根据大小排序,需要传入一个 ...

  4. [leetcode]179. Largest Number最大数

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

  5. 【Leetcode】179. Largest Number

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

  6. Java 特定规则排序-LeetCode 179 Largest Number

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

  7. leetcode 179. Largest Number 求最大组合数 ---------- java

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

  8. Java for LeetCode 179 Largest Number

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

  9. [LeetCode] 179. Largest Number 解题思路

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

  10. [leetcode sort]179. Largest Number

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

随机推荐

  1. 行内块和文字垂直对齐vertical-agign

    vertical-align 垂直对齐 (对于块级元素无效,主要用来控制表单或者图片与文字对齐的) 图片和文字默认是基线对齐 属性: baseline 基线 top 顶线 middle 中线 bott ...

  2. 0502 xss 实验

    0x01 dvwa xss(reflected) 1.1 Security Level: low use the typical <script>alert(1)</script&g ...

  3. Spring之Redis访问(Spring-data-redis)

    Spring-data-redis,是spring-data框架中,比较常用的,基于key-value键值对的数据持久层框架.Spring-data-redis,是一个基于Template模板开发的数 ...

  4. 文件的空间使用和IO统计

    数据库占用的存储空间,从高层次来看,可以查看数据库文件(数据文件,日志文件)占用的存储空间,从较细的粒度上来看,分为数据表,索引,分区占用的存储空间.监控数据库对象占用的硬盘空间,包括已分配,未分配, ...

  5. 【python+beautifulsoup4】Python中安装bs4后,pycharm报错ModuleNotFoundError: No module named 'bs4'

    本文主要分享关于在对应python版本中安装beautifulsoup之后,在代码执行时还会提示“No module named 'bs4'”的问题. 安装beautifsoup4 在命令窗口执行 p ...

  6. Django安装和介绍

    在CMD和pycharm的安装方法. 先说CMD的安装方法 1,使用pip3 install django 2,进入c:python\Scripts 3,django-admin.exe startp ...

  7. linux入门常用指令1.配置本地yum源

    创建光盘挂载点 [root@localhost /]# mkdir /mnt/cdrom 挂载光盘 #挂载光盘 [root@localhost /]# mount /dev/cdrom /mnt/cd ...

  8. nodejs建站+github page 建站问题总结

    本文介绍 昨天吃晚饭的时候,在B站偶然看到一个关于搭建自己博客的视频,过程讲的很详细,于是就有了自己想尝试一下的冲动,所以,在晚上的时候,尝试了下,但是,过程并没有视频中说的那么顺利,看了网上很多帖子 ...

  9. Base64编码与解码的作用

    1.便于网络传输. 2.不可见性. 3.适合在http,mime协议下快速传输数据. 4 区别于加密,Base64是可以解码的,编码是 公开的,Base 64编码,任何人都可以解码

  10. 使用原生js 实现点击消失效果

    JQ版 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title ...