当前位置:网站首页>面试题 01.05. 一次编辑
面试题 01.05. 一次编辑
2022-07-27 23:29:00 【欢迎来到对抗路】
题目要求:
字符串有三种编辑操作:插入一个英文字符、删除一个英文字符或者替换一个英文字符。 给定两个字符串,编写一个函数判定它们是否只需要一次(或者零次)编辑。
示例 1:
输入:
first = "pale"
second = "ple"
输出: True
示例 2:
输入:
first = "pales"
second = "pal"
输出: False
class Solution {
public:
bool oneEditAway(string first, string second) {
int s1, s2;
s1 = first.size();
s2 = second.size();
int len = s1 - s2;
if(len < 0) return oneEditAway(second, first);//保证第一个字符串长度更长
if(len > 1) return false;//若两个字符串的长度差超过2,则返回
int i = 0, j = 0, s = 0;//s表示不等的字母数
while(i < s1 && j < s2)//遍历两个字符串
{
if(first[i] != second[j])
{
s++;//若字母不相等,s+1
if(len == 1)//两个字符串长度不等时单独考虑
{
i++;
continue;
}
}
i++;
j++;
}
if(s < 2)
return true;
else
return false;
}
};
边栏推荐
- At the meeting on June 19, SMIC may set the fastest listing record in China!
- 3年经验想拿20K,居然面了半个月都没拿到?
- 【游戏】任天堂Nintendo Switch超详细购买/使用指南以及注意事项(根据自己使用持续更新中...)
- Centralized management of clusters
- Gazebo 控制实例
- 如何让数字零售承接起流量时代和留量时代的发展重任,或许才是关键所在
- “蔚来杯“2022牛客暑期多校训练营3 补题题解(A、C、J)
- 测试人员需要了解的软件流程
- Meguiar sued liandian for secret theft and sentenced: liandian was fined NT $100million and three employees were sentenced!
- EWM收货ECC交货单校验逻辑问题
猜你喜欢

Transplant QT system for i.mx6ull development board - cross compile QT code

"Wei Lai Cup" 2022 Niuke summer multi school training camp 3 supplementary problem solution (a, C, J)

How the test architects of bat factories interpret various disputes of the test platform

逻辑回归原理

Develop plug-ins for the recording function of flutter

Knowledge of two-dimensional array

Qlib教程——基于源码(二)本地数据保存与加载

HarmonyOS 3正式发布:鸿蒙手机流畅安全,鸿蒙终端常用常新

Thoroughly understand kubernetes scheduling framework and plug-ins

EWM receiving ECC delivery note verification logic problem
随机推荐
Tool function: pay the non empty field value in one workspace to the same field in another workspace
软件测试面试题:think_time的作用是什么?
登录功能实现
【游戏】任天堂Nintendo Switch超详细购买/使用指南以及注意事项(根据自己使用持续更新中...)
Data problems can also be found if there is a space at the end of the field value of MySQL query criteria
同心向前,Google Play 十周年啦!
实现ABCD字母递增
Token is used in nodejs
ICML2022 | 在线决策Transformer
Meguiar sued liandian for secret theft and sentenced: liandian was fined NT $100million and three employees were sentenced!
国产NB-IoT芯片厂商芯翼信息科技获2亿元A+轮融资
From functional testing to automated testing, my monthly salary has exceeded 30k+, and I have 6 years of testing experience.
Storage practices for high-performance computing scenarios, see here
Cesium add annular diffusion ripple
2022/07/27 learning notes (Day17) code blocks and internal classes
Cesium add dynamic pop-up
In April, global smartphone shipments fell 41% year-on-year, and Huawei surpassed Samsung to become the world's first for the first time
软件测试面试题:性能测试指标有哪些?
Day 013 一维数组练习
如何让数字零售承接起流量时代和留量时代的发展重任,或许才是关键所在