当前位置:网站首页>Find the longest substring length satisfying the condition
Find the longest substring length satisfying the condition
2022-06-25 17:42:00 【Python Encyclopedia】
Given a string S The rules of change : Swap characters at any two different positions in the string Input description : A string of lowercase letters Output description : Transform as required to get the minimum string example
Input abcdef
Output abcdef
example 2:
Input bcdefa
Output acdefb
s Are all lowercase characters 1<=s.length<=1000
Their thinking :
Violent solution , Convert string to list , One by one , Determine whether the current character is the remaining string ( Contain itself ) Minimum character of , If it is , Then proceed to the next ; If not , Then the position of the smallest character is recorded , And exchange the current character with the minimum character once ,break Can , Because it can only be exchanged once
str1=input()
i=0
list1=list(str1)
print(list1)
while i<len(list1):
minchar=min(list1[i:])
if list1[i]==minchar:
i+=1
else:
tem=list1[i]
location=list1.index(minchar)
list1[i]=minchar
list1[location]=tem
break
print(''.join(list1))边栏推荐
- Jerry's addition of encrypted file playback function [chapter]
- Precautions for using Jerry's timer [chapter]
- What are the steps for launching the mobile ERP system? It's important to keep it tight
- How does LSF see whether the job reserved slot is reasonable?
- [compilation principle] overview
- About queryinterface functions
- 国泰君安证券靠谱吗?是否合法?开股票账户安全吗?
- Vscode / * * generate function comments
- C语言中%含义
- 【Matlab】数据插值
猜你喜欢

Assembly language (5) register (memory access)

Super Full Metal PBR Multi - channel Mapping Materials website collation

Operating steps for installing CUDA in win10 (continuous improvement)

Intelligent dialog 01 redis installation

College Students' hot summer exchange, Rog star product phantom 16 flipped version / phantom 13 / phantom x appointment
![[compilation principle] lexical analysis](/img/b2/8f7dea3944839e27199b28d903d9f0.png)
[compilation principle] lexical analysis

HMS Core机器学习服务实现同声传译,支持中英文互译和多种音色语音播报

Langage d'assemblage (5) Registre (accès à la mémoire)

How high does UART baud rate require for clock accuracy?

学习太极创客 — MQTT(二)MQTT 基本原理
随机推荐
【UVM实战 ===> Episode_2 】~ VIP、VIP的开发、VIP的发布
CGI connects to database through ODBC
Treasure and niche Chinese painting 3D texture material website sharing
golang sort slice int
Utilisation de diskgenius pour augmenter la capacité du disque système C
About Equilibrium - Simplified bottleneck model
Precautions for use of Jerry's SPI slave [chapter]
配电室环境的分布式远程管理
使用DiskGenius拓展系统盘C盘的容量
Is Guotai Junan Securities reliable? Is it legal? Is it safe to open a stock account?
Interrupt operation: abortcontroller learning notes
Bilstm and CRF
Automatic submission for the next education day
[compilation principle] overview
WPF development essays Collection - ECG curve drawing
观察者模式之通用消息发布与订阅
Essential characteristics of convolution operation +textcnn text classification
WARNING: Unsupported upgrade request.
[efficiency] another note artifact is open source!
使用DiskGenius拓展系統盤C盤的容量