当前位置:网站首页>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)
边栏推荐
- 2020ICPC 江西省赛热身赛 E.Robot Sends Red Packets(dfs)
- Continuous maximum sum and judgement palindrome
- Microservices and related component concepts
- Concepts of phase velocity and phase in transmission line theory
- (2022牛客多校二)K-Link with Bracket Sequence I(动态规划)
- Zhou Chen, vice president of zhanrui market, responded to everything about 5g chip chunteng 510!
- 2020icpc Jiangxi warm up e.robot sends red packets (DFS)
- Difference between NPX and NPM
- 2021 ICPC Shaanxi warm up match b.code (bit operation)
- Base64 (conversion between string and Base64 string)
猜你喜欢

Leetcode 237. 删除链表中的节点
![(14) [driver development] configuration environment vs2019 + wdk10 write XP driver](/img/90/0d94d26be8128d77de65919763fda5.png)
(14) [driver development] configuration environment vs2019 + wdk10 write XP driver

Siggraph 2022 -- rendering iridescent rock dove neck feathers

Amazoncaptcha 95%成功率绕过亚马逊IP验证码

PHP warehouse inventory management system source code WMS source code

HTB-Optimum

Leetcode 202. 快乐数(一点都不快乐)

新时代生产力工具——FlowUs 息流全方位评测

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

Leetcode 202. happy number (not happy at all)
随机推荐
R language uses data.table function to create data.table data (use: operator to create continuous numeric vector)
Y76. Chapter IV Prometheus large factory monitoring system and practice -- Prometheus advanced (VII)
Big talk · book sharing | Haas Internet of things device cloud integrated development framework
传输线理论之相速、相位等的概念
HTB-Granpa
Obj file format and.Mtl file format
Ffmpeg notes (I) fundamentals of audio and video
编程大杂烩(二)
同条网线电脑正常上网,手机连接wifi成功,但是无法访问互联网
Introduction to interface in SystemVerilog
Microservices and related component concepts
Get URL of [url reference]? For the following parameters, there are two ways to get the value of the corresponding parameter name and convert the full quantity to the object structure
Introduction summary of using unirx in unity
VIM configuring golang development environment
Continuous maximum sum and judgement palindrome
2020ICPC 江西省赛热身赛 E.Robot Sends Red Packets(dfs)
Softing pngate series gateway: integrate PROFIBUS bus into PROFINET network
Microservice gateway component
Leetcode 0121. the best time to buy and sell stocks - simulation from back to front
The u-collapse component of uniapp mobile uview is highly init