python 排序 由大到小
2024-08-30 06:51:17
import functools class Solution:
# @param {integer[]} nums
# @return {string}
def largestNumber(self, nums): def comparator(x, y): # inputs are string representations of non-negative ints
if x+y > y+x: # no need to convert to int because x+y and y+x are same length
return - # so lexicographic string sort behaves like numeric sort
else:
return nums = list(map(str, nums)) # convert to strings
nums.sort(key=functools.cmp_to_key(comparator)) return nums
ls=[,,,,,]
x=Solution()
print(x.largestNumber(ls))
输出
['', '', '', '', '', '']
[Program finished]
最新文章
- Java 之 数据库编程(JDBC)
- linq lamada
- Git合并特定commits 到另一个分支
- C语言编译链接
- C/C++面试小知识点
- 简单的背包变形HDU1203,HDU2955
- 【转】Java中字符串中子串的查找共有四种方法(indexof())
- Ubuntu下Qt项目的部署
- Android ImageView 点击更换头像
- 拔高课程_day14_课堂笔记
- 【Selenium】Selenium1
- glog 使用
- 3.sass的数据类型与函数
- Cocos2D:塔防游戏制作之旅(十五)
- Mesos源码分析(15): Test Executor的运行
- 【转】vmware的macos中apple ID一直登陆不上解决 ---(伪造smbios设备信息)
- F#周报2019年第17期
- MySQL索引原理以及类型
- ASP.NET Core分布式项目实战-目录
- Node + Express + vue2.0 + Webpack项目实践
热门文章
- Symfony2 学习笔记之系统路由
- [转载]window.location.href的用法(动态输出跳转)
- Kattis之旅——Perfect Pth Powers
- Spring RestController 请求参数详解
- Vue小案例 之 商品管理------添加商品
- spring boot mvc系列-静态资源配置与MappingHandler拦截器
- mysql读写分离[高可用]
- MS11-050安全漏洞
- 如何用Tensorflow训练模型成pb文件和和如何加载已经训练好的模型文件
- Django使用多数据库