当前位置:网站首页>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))边栏推荐
- Operating steps for installing CUDA in win10 (continuous improvement)
- 使用DiskGenius拓展系統盤C盤的容量
- Old mobile phones turn waste into treasure and serve as servers
- Vscode automatically generates ifndef define ENDIF of header file
- 汇编语言(5)寄存器(内存访问)
- Jerry's ADC_ get_ Incorrect voltage value obtained by voltage function [chapter]
- 智能对话01-redis的安装
- 什么是算子?
- 喜报|海泰方圆通过CMMI-3资质认证,研发能力获国际认可
- RuntimeError: Trying to backward through the graph a second time (or directly access saved variable
猜你喜欢

超全金属PBR多通道贴图素材网站整理

杰理之唤醒口使用注意事项【篇】

配电室环境的分布式远程管理
![[matlab] data interpolation](/img/b8/d7e1a5f7c6f56c8312a1fb5d517ac6.png)
[matlab] data interpolation

Langage d'assemblage (5) Registre (accès à la mémoire)
![[efficiency] another note artifact is open source!](/img/f7/bcea89deaac3e6a6716df7826c1078.jpg)
[efficiency] another note artifact is open source!

喜报|海泰方圆通过CMMI-3资质认证,研发能力获国际认可

杰理之如何给外界输出一个时钟源使用【篇】

CVPR小目标检测:上下文和注意力机制提升小目标检测(附论文下载)

Distinguishing seven kinds of facial expressions by deep separable convolution neural network
随机推荐
Precautions for the use of Jerry's wake-up mouth [chapter]
WARNING: Unsupported upgrade request.
BILSTM和CRF的那些事
WPF development essays Collection - ECG curve drawing
Learning Tai Chi makers - mqtt (I) what is mqtt
超全金属PBR多通道贴图素材网站整理
杰理之定时器使用注意事项【篇】
MySQL mysql-8.0.19-winx64 installation and Navicat connection
golang list to string
Assembly language (6) uses JCC instructions to construct branches and loops
汇编语言(6)使用JCC指令构造分支与循环
Agent white paper - jointly build agents and create the wisdom of the whole scene | cloud library No.21 recommendation
智能对话01-redis的安装
WPF开发随笔收录-心电图曲线绘制
Mobx learning path - powerful "state management tool"
【Matlab】数值微积分与方程求解
Super Full Metal PBR Multi - channel Mapping Materials website collation
数学建模——线性规划
配电室环境的分布式远程管理
Accumulation of some common knowledge points