当前位置:网站首页>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
边栏推荐
- 力扣 1037.有效的回旋镖
- Tp6 realize Commission ranking
- Browse the purpose of point setting
- JVM 类加载机制
- Classification automatique des cellules de modules photovoltaïques par défaut dans les images de lecture électronique - notes de lecture de thèse
- 力扣 459. 重复的子字符串
- 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
- R语言使用ggplot2函数可视化需要构建泊松回归模型的计数目标变量的直方图分布并分析构建泊松回归模型的可行性
- UCloud是基础云计算服务提供商
- Simulate the implementation of string class
猜你喜欢
位运算介绍
MRS离线数据分析:通过Flink作业处理OBS数据
[RT thread env tool installation]
Chapter 9 Yunji datacanvas was rated as 36 krypton "the hard core technology enterprise most concerned by investors"
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!!!
CSDN syntax description
最多可以参加的会议数目[贪心 + 优先队列]
干货分享|DevExpress v22.1原版帮助文档下载集合
The state cyberspace Office released the measures for data exit security assessment: 100000 information provided overseas needs to be declared
九章云极DataCanvas公司获评36氪「最受投资人关注的硬核科技企业」
随机推荐
CSDN语法说明
My creation anniversary
Some important knowledge of MySQL
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
el-upload上传组件的动态添加;el-upload动态上传文件;el-upload区分文件是哪个组件上传的。
mock. JS returns an array from the optional data in the object array
PMP對工作有益嗎?怎麼選擇靠譜平臺讓備考更省心省力!!!
831. KMP string
LeetCode_7_5
R language ggplot2 visualization: use the ggstripchart function of ggpubr package to visualize the dot strip plot, set the position parameter, and configure the separation degree of different grouped
位运算介绍
R语言fpc包的dbscan函数对数据进行密度聚类分析、查看所有样本的聚类标签、table函数计算聚类簇标签与实际标签构成的二维列联表
Kubernetes——kubectl命令行工具用法详解
让这个 CRMEB 单商户微信商城系统火起来,太好用了!
小试牛刀之NunJucks模板引擎
力扣 2315.统计星号
Ucloud is a basic cloud computing service provider
BI的边界:BI不适合做什么?主数据、MarTech?该如何扩展?
微信公众号OAuth2.0授权登录并显示用户信息
Time tools