当前位置:网站首页>剑指 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 physical interface
- VIM configuring golang development environment
- C Programming -- the solution of dynamic programming of "the sum of the largest subarray"
- 剑指 Offer 05. 替换空格
- Dynamic planning learning notes
- Vim查找替换及正则表达式的使用
- Why is it that all the games are pseudorandom and can't make true random?
- systemVerilog中automatic用法
- 聊聊 Redis 是如何进行请求处理
- Talk about how redis handles requests
猜你喜欢

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

Programming hodgepodge (I)

Working principle and precautions of bubble water level gauge

Microservices and related component concepts

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

Arm PWN basic tutorial

ECS is exclusive to old users, and the new purchase of the remaining 10 instances is as low as 3.6% off

50 places are limited to open | with the news of oceanbase's annual press conference coming!

微服务 - 配置中心 - Nacos

npx和npm区别
随机推荐
sqlilabs less-29
2020ICPC 江西省赛热身赛 E.Robot Sends Red Packets(dfs)
求求你别再用 System.currentTimeMillis() 统计代码耗时了,真的太 Low 了!
ECS is exclusive to old users, and the new purchase of the remaining 10 instances is as low as 3.6% off
An SQL execution process
CSDN编程挑战赛之数组编程问题
LCP plug-in creates peer-to-peer 802.1ad interface
Adaptation dynamics | in June, sequoiadb completed mutual certification with five products
sqlilabs less-28~less-8a
微服务 - 远程调用(Feign组件)
Detailed explanation of stepn chain game system development mode (Sports money making mode)
Productivity tool in the new era -- flowus information flow comprehensive evaluation
Idea commonly used 10 shortcut keys
Application of hard coding and streaming integration scheme based on spice protocol in cloud games
HTB-Granpa
Microservice configuration center Nacos
ERA5数据集说明
Openfegin remote call lost request header problem
Sword finger offer special shock edition day 9
Realsense D435i 深度图优化_高精度模式