2 Star 0 Fork 0

xinanXu/myleetcode

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
面试题 01.05.cpp 676 Bytes
Copy Edit Raw Blame History
xinanXu authored 2023-03-02 17:50 . 面试题 01.05. 一次编辑
class Solution {
public:
bool oneEditAway(string first, string second) {
if (!first.size() && !second.size()) return true;
if (abs<int>(first.size() - second.size()) >= 2) return false;
if (first.size() > second.size()) swap(first, second);
int len1 = first.size(), len2 = second.size();
int i = 0;
for (i = 0; i < len1; i++)
if (first[i] != second[i]) break;
if (i == len1) return true;
for (len1--, len2-- ; len1 >= 0 && len2 >= 0; len1--, len2--) {
if (first[len1] != second[len2]) break;
}
if (len2 - i) return false;
return true;
}
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/DearAtri/myleetcode.git
git@gitee.com:DearAtri/myleetcode.git
DearAtri
myleetcode
myleetcode
master

Search