当前位置:网站首页>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
边栏推荐
- A pot of stew, a collection of common commands of NPM and yarn cnpm
- Dynamic addition of El upload upload component; El upload dynamically uploads files; El upload distinguishes which component uploads the file.
- Tp6 realize Commission ranking
- mock.js从对象数组中任选数据返回一个数组
- Time tools
- Navicat连接2002 - Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘解决
- ASP. Net kindergarten chain management system source code
- IP tools
- Visual Studio 插件之CodeMaid自动整理代码
- LeetCode_ 7_ five
猜你喜欢
![[RT thread env tool installation]](/img/bc/9b39651d40a240f0893200793f67e9.png)
[RT thread env tool installation]

mysql 的一些重要知识

力扣 2319. 判断矩阵是否是一个 X 矩阵

Open source heavy ware! Chapter 9 the open source project of ylarn causal learning of Yunji datacanvas company will be released soon!

LeetCode_ 7_ five

使用高斯Redis实现二级索引

【STL】vector

YoloV6:YoloV6+Win10---训练自己得数据集

Nunjuks template engine

9 原子操作类之18罗汉增强
随机推荐
[auto.js] automatic script
项目经理『面试八问』,看了等于会了
浏览积分设置的目的
小试牛刀之NunJucks模板引擎
【Confluence】JVM内存调整
el-upload上传组件的动态添加;el-upload动态上传文件;el-upload区分文件是哪个组件上传的。
力扣 912.排序数组
Version selection of boot and cloud
【STL】vector
pom. Brief introduction of XML configuration file label function
Semantic SLAM源码解析
Is PMP beneficial to work? How to choose a reliable platform to make it easier to prepare for the exam!!!
论文解读(ValidUtil)《Rethinking the Setting of Semi-supervised Learning on Graphs》
[confluence] JVM memory adjustment
831. KMP string
力扣 989. 数组形式的整数加法
Mysql, sqlserver Oracle database connection mode
R language ggplot2 visualization: use the ggecdf function of ggpubr package to visualize the grouping experience cumulative density distribution function curve, and the linetype parameter to specify t
R language ggplot2 visualization: use the ggviolin function of ggpubr package to visualize the violin diagram, set the palette parameter to customize the filling color of violin diagrams at different
openEuler 资源利用率提升之道 01:概论