当前位置:网站首页>程序员面试金典面试题 01.05. 一次编辑
程序员面试金典面试题 01.05. 一次编辑
2022-07-22 09:21:00 【yijun009】
面试题 01.05. 一次编辑
class Solution {
public:
bool oneEditAway(string first, string second) {
int first_l = first.length();
int second_l = second.length();
if (first_l - second_l == 0){
int count = 0;
for (int i = 0; i<first_l; i++){
if (first[i] != second[i]) count++;
}
if (count>1) return false;
return true;
}
else if (first_l - second_l == -1){
for (int i = 0; i<first_l; i++){
if (first[i] != second[i]){
for (int j = 0; j<first_l - i; j++){
if (first[first_l - j - 1] != second[second_l - j - 1]) return false;
}
return true;
}
}
return true;
}
else if (first_l - second_l == 1)
{
for (int i = 0; i<second_l; i++)
{
if (first[i] != second[i])
{
for (int j = 0; j<second_l - i; j++)
{
if (first[first_l - j - 1] != second[second_l - j - 1]){
return false;
}
}
return true;
}
}
return true;
}
else{
return false;
}
}
};
这次的题出现
- 不是所有的判断路径都有返回值的问题
- 倒过来遍历时下标取值问题
- 又出现搞不清对象,明明是想对第一个字符串进行遍历,却对使用第二个字符串的长度。程序一长读起来就麻烦。边写边测试。
这位大佬写得好,链接: link.
边栏推荐
- 模块TensorFlow中没有Session
- Summary 20220211
- Leetcode 304. two dimensional area and retrieval - matrix immutable
- PTA search tree judgment
- PTA 6-11 find the median of self-determined type element sequence (25 points)
- PAT乙级1019 数字黑洞 (20 分) (测点错误可能原因)
- Go concurrency mode: pipeline and cancellation
- Data Lake simple record
- LeetCode 720. 词典中最长的单词
- Log4j log configuration details
猜你喜欢
VLFeat、pydot配置
LeetCode: 185. 部门工资前三高的所有员工
Six dimensional space
Flink学习笔记(三)Flink安装部署
Flink学习笔记(六)Flink的时间和窗口
Important knowledge points of go language: string, UTF-8 encoding, Rune
STM32+ESP8266+MQTT协议连接OneNet物联网平台
在各类数据库中随机查询n条数据
Caching-sha2-password problem occurred when connecting mysql8.0
6-2-深度优先搜索 地下迷宫探索 (30分)
随机推荐
位与:一个数&1的结果
解决不能维持IntelliJ 之 Target bytecode Version版本号
LeetCode 105. 从前序与中序遍历序列构造二叉树
01. Open closed principle
Leetcode 114. expand binary tree into linked list
递归求简单交错幂级数的部分和 (15分)
Summary 20220209
LeetCode:626. 换座位
Pat class B 1010 univariate polynomial derivation (problem meaning understanding)
牛人专栏-博客汇总
Leetcode 105. constructing binary trees from preorder and inorder traversal sequences
Qt | boîtes de dialogue modales et non modales qdialog
Go concurrency mode: pipeline and cancellation
strncpy() 复制字符串(受长度限制)
06. Liskov Substitution Principle (LSP)
项目启动过后,一直循环加载mapper xml文件
LeetCode 304. 二维区域和检索 - 矩阵不可变
There is no session in the tensorflow module
AMH multiple MySQL versions coexist?
Summary 20220214