当前位置:网站首页>Force buckle 1790 Can two strings be equal by performing string exchange only once
Force buckle 1790 Can two strings be equal by performing string exchange only once
2022-07-07 20:06:00 【Tomorrowave】
1790. Can performing only one string exchange make two strings equal
Give you two strings of equal length s1 and s2 . once String swapping The operation steps are as follows : Select two subscripts in a string ( It doesn't have to be different ), And exchange the characters corresponding to the two subscripts .
If the One of the strings perform At most one string exchange You can make two strings equal , return true ; otherwise , return false .
Example 1:
Input :s1 = “bank”, s2 = “kanb”
Output :true
explain : for example , In exchange for s2 The first and last characters in can get “bank”
Ideas :
Matching algorithm idea . string matching
Code section
class Solution:
def areAlmostEqual(self, s1: str, s2: str) -> bool:
s1,s2=list(s1),list(s2)
if len(s1)!=len(s2):
return False
cnt=[]
for i in range(len(s1)):
if s1[i]!=s2[i] and len(cnt)<2 :
cnt.append(i)
if len(cnt)==2:
s1[cnt[0]],s1[cnt[1]]= s1[cnt[1]],s1[cnt[0]]
return s1==s2
边栏推荐
- JVM 类加载机制
- How to buy stocks on your mobile phone and open an account? Is it safe to open an account
- CSDN语法说明
- Kubernetes——kubectl命令行工具用法详解
- R语言ggplot2可视化:使用ggpubr包的ggqqplot函数可视化QQ图(Quantile-Quantile plot)
- Semantic slam source code analysis
- CUDA versions are inconsistent, and errors are reported when compiling apex
- pom.xml 配置文件标签:dependencies 和 dependencyManagement 区别
- The DBSCAN function of FPC package of R language performs density clustering analysis on data, checks the clustering labels of all samples, and the table function calculates the two-dimensional contin
- Some arrangements about oneself
猜你喜欢

模拟实现string类

Automatic classification of defective photovoltaic module cells in electroluminescence images-論文閱讀筆記
![[RT thread env tool installation]](/img/bc/9b39651d40a240f0893200793f67e9.png)
[RT thread env tool installation]

项目经理『面试八问』,看了等于会了

Classification automatique des cellules de modules photovoltaïques par défaut dans les images de lecture électronique - notes de lecture de thèse

剑指 Offer II 013. 二维子矩阵的和

Le PGR est - il utile au travail? Comment choisir une plate - forme fiable pour économiser le cœur et la main - d'œuvre lors de la préparation de l'examen!!!

ASP. Net learning & ASP's one word

MRS离线数据分析:通过Flink作业处理OBS数据

Nunjuks template engine
随机推荐
Some arrangements about oneself
831. KMP string
LC: string conversion integer (ATOI) + appearance sequence + longest common prefix
CSDN语法说明
[confluence] JVM memory adjustment
力扣 2319. 判断矩阵是否是一个 X 矩阵
Automatic classification of defective photovoltaic module cells in electroluminescence images-論文閱讀筆記
R语言dplyr包mutate_at函数和min_rank函数计算dataframe中指定数据列的排序序号值、名次值、将最大值的rank值赋值为1
Le PGR est - il utile au travail? Comment choisir une plate - forme fiable pour économiser le cœur et la main - d'œuvre lors de la préparation de l'examen!!!
mock. JS returns an array from the optional data in the object array
ASP. Net learning & ASP's one word
Dynamic addition of El upload upload component; El upload dynamically uploads files; El upload distinguishes which component uploads the file.
多个线程之间如何协同
MRS离线数据分析:通过Flink作业处理OBS数据
华南X99平台打鸡血教程
JVM GC garbage collection brief
【STL】vector
841. String hash
Introduction to bit operation
A pot of stew, a collection of common commands of NPM and yarn cnpm