当前位置:网站首页>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;
}
};
边栏推荐
- Icml2022 | online decision transformer
- C#学习笔记----C#连接MySQL数据库
- 8000 word explanation of OBSA principle and application practice
- 普通设备能不能接入TSN时间敏感网络?
- Lua advanced
- How to make digital retail undertake the development task of the era of traffic and retention may be the key
- 【样式集合1】tab 栏
- C language main function transfer parameters
- Data problems can also be found if there is a space at the end of the field value of MySQL query criteria
- 梳理 SQL 性能优化,收藏经典!
猜你喜欢

idea常用的快捷键汇总

Let's move forward together, the 10th anniversary of Google play!

Anfulai embedded weekly report no. 275: 2022.07.18--2022.07.24

Cesium add dynamic pop-up

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

Summary of common shortcut keys in idea

Unity shader introduction Essentials - basic texture

Login function implementation

我的富二代朋友

I want to get 20K after 3 years of experience, but I haven't got it for half a month?
随机推荐
Can anime characters become "real people"? Paddegan helps you find the TA of "tear man"
“蔚来杯“2022牛客暑期多校训练营3 补题题解(A、C、J)
My rich second generation friend
Baidu PaddlePaddle easydl: when AI enters the factory, "small bearing" can also turn "big industry"
JG data reset (WD)
彻底搞懂kubernetes调度框架与插件
Leetcode 2347. the best poker hand
BYD semiconductor completed the a+ round financing of 800million yuan: 30 well-known investment institutions entered the market, with a valuation of 10.2 billion yuan!
"Wei Lai Cup" 2022 Niuke summer multi school training camp 3 supplementary problem solution (a, C, J)
Software test interview question: how to prepare test data? How to prevent data pollution?
Briefly understand namenode and datanode
S-RPN: Sampling-balanced region proposal network for small crop pest detection
Oracle RAC cluster file directory migration
Count the number of given strings in a string
“你“想当测试/开发程序员吗?努力发芽的我们......
8000字讲透OBSA原理与应用实践
彻底搞懂kubernetes调度框架与插件
迅为i.MX6ULL开发板Qt系统移植-交叉编译Qt代码
idea常用的快捷键汇总
Introduction to QT drawing system