当前位置:网站首页>剑指 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)
边栏推荐
- Analyzing the principle of DNS resolution in kubernetes cluster
- LeetCode 15:三数之和
- sqlilabs less-28~less-8a
- 新时代生产力工具——FlowUs 息流全方位评测
- R language ggpubr package ggarrange function combines multiple images and annotates_ Figure add annotation, annotation, annotation information for the combined image, and use the right parameter to ad
- R language uses rowmedians function to calculate the row data median value of all data rows in dataframe
- [typescript manual]
- An SQL execution process
- Realsense d435i depth map optimization_ High precision mode
- Leetcode 0121. the best time to buy and sell stocks - simulation from back to front
猜你喜欢

sqlilabs less-28~less-8a

Leetcode 15: sum of three numbers

10、渲染基础

Array programming problem of CSDN programming challenge

C Programming -- the solution of dynamic programming of "the sum of the largest subarray"

Easyrecovery free data recovery tool is easy to operate and restore data with one click

HTB-Arctic

微服务 - Hystrix 熔断器

Talk about how redis handles requests

Softing pngate series gateway: integrate PROFIBUS bus into PROFINET network
随机推荐
Atof(), atoi(), atol() functions [detailed]
easyrecovery免费数据恢复工具操作简单一键恢复数据
R language obtains the data row where the nth maximum value of the specified data column is located in the data.table data
出于数据安全考虑,荷兰教育部要求学校暂停使用 Chrome 浏览器
Terminate 5g chip cooperation! The official response of Intel and zhanrui came
msys2常用配置
G1 garbage collector
Big talk · book sharing | Haas Internet of things device cloud integrated development framework
Automatic usage in SystemVerilog
LeetCode第302场周赛
background
Unity接入ChartAndGraph图表插件
LCP plug-in creates peer VLAN interface
Linear algebra (3)
Differences and application directions of GPS, base station and IP positioning
编程大杂烩(二)
R language ggpubr package ggarrange function combines multiple images and annotates_ Figure add annotation, annotation, annotation information for the combined image, and use the right parameter to ad
Unity中使用UniRx入门总结
Leetcode 0121. the best time to buy and sell stocks - simulation from back to front
sqlilabs less-28~less-8a