当前位置:网站首页>Interview question 01.05. Primary editing
Interview question 01.05. Primary editing
2022-07-28 01:39:00 【Welcome to the confrontation Road】
Subject requirements :
There are three editing operations for Strings : Insert an English character 、 Delete an English character or replace an English character . Given two strings , Write a function to determine if they only need to be done once ( Or zero times ) edit .
Example 1:
Input :
first = "pale"
second = "ple"
Output : True
Example 2:
Input :
first = "pales"
second = "pal"
Output : 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);// Ensure that the first string is longer
if(len > 1) return false;// If the length difference between two strings exceeds 2, Then return to
int i = 0, j = 0, s = 0;//s Indicates unequal numbers of letters
while(i < s1 && j < s2)// Traverse two strings
{
if(first[i] != second[j])
{
s++;// If the letters are not equal ,s+1
if(len == 1)// Consider separately when the length of two strings is different
{
i++;
continue;
}
}
i++;
j++;
}
if(s < 2)
return true;
else
return false;
}
};
边栏推荐
- Fluent call interface UI
- Niuke multi School Game 3 A, c+ weight segment tree
- 3000 words and 11 pictures hard core popular science: what is edge computing? What are the connections and differences with cloud computing?
- Oracle RAC cluster file directory migration
- 软件测试面试题:如何发现数据库的相关问题?
- 文章复现:超分辨率网络FSRCNN
- Kibana6.2.4 version update x-pack certification
- S-RPN: Sampling-balanced region proposal network for small crop pest detection
- Data problems can also be found if there is a space at the end of the field value of MySQL query criteria
- 8000字讲透OBSA原理与应用实践
猜你喜欢

Codeforces summer training weekly (7.21~7.27)

Summary of common shortcut keys in idea

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

Codeforces summer training weekly (7.14~7.20)

LeetCode 2347. 最好的扑克手牌

Login function implementation

Flutter 通话界面UI

8000字讲透OBSA原理与应用实践

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

【样式集合1】tab 栏
随机推荐
Kibana6.2.4 version update x-pack certification
自定义事件
Niuke multi School Game 3 A, c+ weight segment tree
Software process that testers need to know
Advanced MySQL -- stored procedures and custom functions
URDF integrated gazebo
Software testing interview question: where do your performance testing requirements come from?
What is the opening time of London Silver
梳理 SQL 性能优化,收藏经典!
字节月薪28K,分享一波我的自动化测试经验....
对迁移学习中域适应的理解和3种技术的介绍
【分布式开发】之 CAP 原则
Icml2022 | online decision transformer
The understanding of domain adaptation in transfer learning and the introduction of three technologies
Codeforces summer training weekly (7.14~7.20)
Cap principle of [distributed development]
Codeforces暑期训练周报(7.14~7.20)
Spreadsheet export excel table
Gazebo control example
Leetcode 2341. How many pairs can an array form