当前位置:网站首页>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
边栏推荐
- Semantic SLAM源码解析
- [auto.js] automatic script
- 吞吐量Throughout
- Make this crmeb single merchant wechat mall system popular, so easy to use!
- R语言ggplot2可视化:使用ggpubr包的ggqqplot函数可视化QQ图(Quantile-Quantile plot)
- ASP. Net gymnasium integrated member management system source code, free sharing
- R language dplyr package select function, group_ The by function, filter function and do function obtain the third largest value of a specific numerical data column in a specified level in a specified
- pom. Brief introduction of XML configuration file label function
- MSE API学习
- 力扣 599. 两个列表的最小索引总和
猜你喜欢

Simulate the implementation of string class

Some important knowledge of MySQL

8 CAS

The state cyberspace Office released the measures for data exit security assessment: 100000 information provided overseas needs to be declared
![最多可以参加的会议数目[贪心 + 优先队列]](/img/f3/e8e939e0393efc404cc159d7d33364.png)
最多可以参加的会议数目[贪心 + 优先队列]

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

vulnhub之school 1

Ways to improve the utilization of openeuler resources 01: Introduction

模拟实现string类

MRS离线数据分析:通过Flink作业处理OBS数据
随机推荐
Mysql, sqlserver Oracle database connection mode
Cloud component development and upgrading
Version selection of boot and cloud
vulnhub之school 1
Training IX basic configuration of network services
让这个 CRMEB 单商户微信商城系统火起来,太好用了!
银行理财产品怎么买?需要办银行卡吗?
pom.xml 配置文件标签:dependencies 和 dependencyManagement 区别
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
How to buy bank financial products? Do you need a bank card?
使用高斯Redis实现二级索引
Semantic SLAM源码解析
Tp6 realize Commission ranking
使用高斯Redis实现二级索引
R language dplyr package mutate_ At function and min_ The rank function calculates the sorting sequence number value and ranking value of the specified data column in the dataframe, and assigns the ra
开源OA开发平台:合同管理使用手册
一锅乱炖,npm、yarn cnpm常用命令合集
8 CAS
ASP.NET体育馆综合会员管理系统源码,免费分享
Semantic slam source code analysis