当前位置:网站首页>剑指 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)
边栏推荐
- The difference between $write and $display in SystemVerilog
- Switch NPM source to private source library
- npx和npm区别
- [cloud co creation] design Huawei cloud storage architecture with the youngest cloud service hcie (Part 1)
- Typera+picgo+ Alibaba cloud OSS setup and error reporting solution [reprint]
- R language obtains the data row where the nth maximum value of the specified data column is located in the data.table data
- Obj file format and.Mtl file format
- Introduction summary of using unirx in unity
- sqlilabs less-29
- 微服务及相关组件概念
猜你喜欢

HTB-Granpa

Programming hodgepodge (II)

Leetcode 237. delete nodes in the linked list

Sword finger offer 05. replace spaces

Linear algebra (3)

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

Working principle and precautions of bubble water level gauge

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

PHP warehouse inventory management system source code WMS source code

编程大杂烩(二)
随机推荐
LCP plug-in creates peer-to-peer physical interface
Single sign on (one sign on, available everywhere)
10、渲染基础
VIM search and replacement and the use of regular expressions
暑期总结2
动态规划学习笔记
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
出于数据安全考虑,荷兰教育部要求学校暂停使用 Chrome 浏览器
HTB-Arctic
Working principle and precautions of bubble water level gauge
An SQL execution process
计算BDP值和wnd值
Airserver 7.3.0 Chinese version mobile device wireless transmission computer screen tool
Unity accesses chartandgraph chart plug-in
Three billion dollars! Horizon becomes the world's highest valued AI chip Unicorn
HTB-Granpa
ERA5数据集说明
Introduction to interface in SystemVerilog
After Oracle user a deletes a table under user B's name, can user B recover the deleted table through the recycle bin?
Flexible layout summary