当前位置:网站首页>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
边栏推荐
- 831. KMP string
- 线性基
- Chapter 20 using work queue manager (3)
- 转置卷积理论解释(输入输出大小分析)
- R语言ggplot2可视化:使用ggpubr包的ggdensity函数可视化分组密度图、使用stat_overlay_normal_density函数为每个分组的密度图叠加正太分布曲线
- 力扣599. 两个列表的最小索引总和
- PMP每日一练 | 考试不迷路-7.7
- ASP. Net learning & ASP's one word
- J ü rgen schmidhub reviews the 25th anniversary of LSTM papers: long short term memory All computable metaverses. Hierarchical reinforcement learning (RL). Meta-RL. Abstractions in generative adversar
- R语言ggplot2可视化:使用ggpubr包的ggecdf函数可视化分组经验累积密度分布函数曲线、linetype参数指定不同分组曲线的线型
猜你喜欢

Flink并行度和Slot详解

openEuler 资源利用率提升之道 01:概论

PMP对工作有益吗?怎么选择靠谱平台让备考更省心省力!!!

Some important knowledge of MySQL

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!!!

使用高斯Redis实现二级索引

Detailed explanation of Flink parallelism and slot

Automatic classification of defective photovoltaic module cells in electroluminescence images-论文阅读笔记

关于cv2.dnn.readNetFromONNX(path)就报ERROR during processing node with 3 inputs and 1 outputs的解决过程【独家发布】

【STL】vector
随机推荐
el-upload上传组件的动态添加;el-upload动态上传文件;el-upload区分文件是哪个组件上传的。
关于cv2.dnn.readNetFromONNX(path)就报ERROR during processing node with 3 inputs and 1 outputs的解决过程【独家发布】
sql 常用优化
力扣 1037.有效的回旋镖
最多可以参加的会议数目[贪心 + 优先队列]
IP 工具类
[RT thread env tool installation]
Nunjuks template engine
pom. Brief introduction of XML configuration file label function
Data island is the first danger encountered by enterprises in their digital transformation
Training IX basic configuration of network services
Notes...
剑指 Offer II 013. 二维子矩阵的和
Mysql, sqlserver Oracle database connection mode
论文解读(ValidUtil)《Rethinking the Setting of Semi-supervised Learning on Graphs》
equals 方法
mock. JS returns an array from the optional data in the object array
Make this crmeb single merchant wechat mall system popular, so easy to use!
Detailed explanation of Flink parallelism and slot
IP tools