当前位置:网站首页>剑指 Offer 45. 把数组排成最小的数
剑指 Offer 45. 把数组排成最小的数
2022-07-25 05:41:00 【愈努力俞幸运】
剑指 Offer 45. 把数组排成最小的数
https://leetcode.cn/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/
首先讲解快速排序
快速排序算法_愈努力俞幸运的博客-CSDN博客
https://blog.csdn.net/qq_37891604/article/details/125902608?spm=1001.2014.3001.5501那么,对于这道题,只需把排序规则加到快速排序中
此题求拼接起来的最小数字,本质上是一个排序问题。设数组 numsnums 中任意两数字的字符串为 x和 y ,则规定 排序判断规则 为:
若拼接字符串 x + y > y + x ,则 x应在y右边 ;
反之,若 x + y < y + x ,则 x应在y左边 ;
class Solution:
def minNumber(self, nums):
def qsort(l,r):
if l>=r: return
i,j,key=l,r,strs[l]
while i<j:
while i<j and strs[j]+key>=key+strs[j]:
j-=1
strs[i],strs[j]=strs[j],strs[i]
while strs[i]+key<key+strs[i]:
i+=1
if i>=j:break
strs[i], strs[j] = strs[j], strs[i]
qsort(l, j-1)
qsort(j+1, r)
strs=[str(i) for i in nums]
qsort(0,len(strs)-1)
return ''.join(strs)
边栏推荐
- LCP plug-in creates peer-to-peer 802.1ad interface
- msys2常用配置
- HTB-Beep
- SystemVerilog中$write与$display区别
- Dynamic planning learning notes
- ERA5数据集说明
- VIM configuring golang development environment
- Zhou Chen, vice president of zhanrui market, responded to everything about 5g chip chunteng 510!
- Productivity tool in the new era -- flowus information flow comprehensive evaluation
- Realsense D435i 深度图优化_高精度模式
猜你喜欢
![50: Chapter 5: develop admin management service: 3: develop [query whether the admin user name already exists, interface]; (this interface can only be called when logging in; so we have written an int](/img/1b/b8529b6f1d163a9e5d5dad2b78ce93.png)
50: Chapter 5: develop admin management service: 3: develop [query whether the admin user name already exists, interface]; (this interface can only be called when logging in; so we have written an int

求求你别再用 System.currentTimeMillis() 统计代码耗时了,真的太 Low 了!

sqlilabs less-28~less-8a

Microservice - hystrix fuse

Why is it that all the games are pseudorandom and can't make true random?

Differences and application directions of GPS, base station and IP positioning

npx和npm区别

Microservice gateway component

Idea commonly used 10 shortcut keys

An SQL execution process
随机推荐
Adaptation dynamics | in June, sequoiadb completed mutual certification with five products
TCL shows a number of folding screen mobile phones: the screen and hinge are independently developed!
聊聊 Redis 是如何进行请求处理
Sword finger offer special shock edition day 9
10、渲染基础
2020icpc Jiangxi warm up e.robot sends red packets (DFS)
R language data The table package performs aggregation transforms of data packets and calculates the grouping interquartile range (IQR) of dataframe data
Singing "Seven Mile fragrance" askew -- pay tribute to Jay
出于数据安全考虑,荷兰教育部要求学校暂停使用 Chrome 浏览器
An SQL execution process
Switch NPM source to private source library
Microservice - remote invocation (feign component)
剖析kubernetes集群内部DNS解析原理
JWT(json web token)
Introduction summary of using unirx in unity
Softing pnGate系列网关:将PROFIBUS总线集成到PROFINET网络
Idea commonly used 10 shortcut keys
Three billion dollars! Horizon becomes the world's highest valued AI chip Unicorn
systemverilog中function和task区别
Array programming problem of CSDN programming challenge