当前位置:网站首页>Sword finger offer 45. arrange the array into the smallest number
Sword finger offer 45. arrange the array into the smallest number
2022-07-25 05:46:00 【The harder you work, the luckier you are】
First, let's talk about quick sorting
Fast sorting algorithm _ The harder you work, the luckier your blog -CSDN Blog
https://blog.csdn.net/qq_37891604/article/details/125902608?spm=1001.2014.3001.5501 that , For this question , Just add the sorting rule to the quick sort
This problem is to find the smallest number spliced together , It's essentially a sort problem . Set array numsnums The string of any two numbers in is x and y , It stipulates that Sorting judgment rule by :
If you splice strings x + y > y + x , be x Should be in y On the right ;
conversely , if x + y < y + x , be x Should be in y On the left ;
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)
边栏推荐
- 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
- HTB-Optimum
- uniapp手机端uView的u-collapse组件高度init
- (14)[驱动开发]配置环境 VS2019 + WDK10 写 xp驱动
- ECS is exclusive to old users, and the new purchase of the remaining 10 instances is as low as 3.6% off
- HTB-Granpa
- (15) [driver development] over written copy
- Introduction summary of using unirx in unity
- Difference between NPX and NPM
- Realsense d435i depth map optimization_ High precision mode
猜你喜欢

sqlilabs less-29

An SQL execution process

传输线理论之相速、相位等的概念

CCID released the "Lake warehouse integrated technology research report", and Jushan database was selected as a typical representative of domestic enterprises

(2022牛客多校二)K-Link with Bracket Sequence I(动态规划)

sqlilabs less-28~less-8a

The selection reference of Junzheng T41, T40 and T31 versions are all here

HTB-Optimum

Xiaomi 12s UTRA Leica watermark generation online tool

HTB-Beep
随机推荐
(2022牛客多校)D-Link with Game Glitch(spfa)
Introduction to interface in SystemVerilog
Linear algebra (3)
G1 garbage collector
(Niuke multi school I in 2022) i-chiitoitsu (expected DP)
(15)[驱动开发]过写拷贝
C100: smallest hevc visual IOT MCU
Talk about how redis handles requests
Unity accesses chartandgraph chart plug-in
Airserver 7.3.0 Chinese version mobile device wireless transmission computer screen tool
Easyrecovery free data recovery tool is easy to operate and restore data with one click
线性代数(三)
Softing pnGate系列网关:将PROFIBUS总线集成到PROFINET网络
QT qtextedit setting qscrollbar style sheet does not take effect solution
50:第五章:开发admin管理服务:3:开发【查询admin用户名是否已存在,接口】;(这个接口需要登录时才能调用;所以我们编写了拦截器,让其拦截请求,判断用户是否是登录状态;)
Msys2 common configuration
动态规划学习笔记
HTB-Arctic
Concepts of phase velocity and phase in transmission line theory
Automatic usage in SystemVerilog