leetcode - One Edit Distance
来源:互联网 发布:淘宝搜索算法现状 编辑:程序博客网 时间:2024/06/04 19:51
题目:
One Edit Distance
Given two strings S and T, determine if they are both oneedit distance apart.
Hint:
1. If | n – m | is greater than 1, we know immediately both are not one-editdistance apart.
2. It might help if you consider these cases separately, m == n and m ≠ n.
3. Assume that m is always ≤ n, which greatly simplifies the conditionalstatements. If m > n, we could just simply swap S and T.
4. If m == n, it becomes finding if there is exactly one modified operation. Ifm ≠ n, you do not have to consider the delete operation. Just consider theinsert operation in T.
bool OneEditDistance(const string &s1, const string &s2){if (s1.size() > s2.size())return OneEditDistance(s2, s1);if (s2.size() - s1.size()>1)return false;int i1 = 0, i2 = 0;while (i1 < s1.size()){if (s1[i1] == s2[i2]){++i1;++i2;}elsebreak;}if (i1 == s1.size())return true;++i2;while (i1 < s1.size() && i2<s2.size()){if (s1[i1] == s2[i2]){++i1;++i2;}elsebreak;}return i1 == s1.size();}
0 0
- Leetcode One Edit Distance
- LeetCode - One Edit Distance
- leetcode - One Edit Distance
- #leetcode#One Edit Distance
- [LeetCode]One Edit Distance
- leetcode 161: One Edit Distance
- Leetcode-161.One Edit Distance
- [LeetCode]161. One Edit Distance
- LeetCode 161. One Edit Distance
- Leetcode 161. One Edit Distance
- LeetCode 161.One Edit Distance
- LeetCode 题解(236) : One Edit Distance
- [leetcode] One Edit Distance 解题报告
- LeetCode—161. One Edit Distance
- [Leetcode] 161. One Edit Distance 解题报告
- One Edit Distance
- One Edit Distance
- One Edit Distance
- UIActionSheet的使用
- Centos 6.3 RabbitMQ 安装
- Windows下VMware准备IOS开发环境
- 三角形和矩形相交的判断
- 极点五笔特殊符号输入方法
- leetcode - One Edit Distance
- JAVASE学习笔记:第五章 JAVA面向对象(三)
- java一些注解
- 跟赵薇一起玩转投资
- Leetcode--Median of Two Sorted Array
- 查询GPU是否支持CUDA
- java函数参数类型后添加三点的用法
- 玩转PS“渐变窗口”
- 【grunt整合版】30分钟学会使用grunt打包前端代码