LeetCode – Refresh – One Edit Distance
2015-03-21 15:17
417 查看
Scanning from start to end. If find a mismatch and one is larger size, keep search from the previous char of shorter one.
Finally check whether found a mismatch OR still have a larger size string.
Finally check whether found a mismatch OR still have a larger size string.
class Solution { public: bool isOneEditDistance(string s, string t) { if (s.size() > t.size()) { return isOneEditDistance(t, s); } if (t.size() - s.size() > 1) return false; bool found = false; for (int i = 0, j = 0; j < t.size(); i++, j++) { if (s[i] != t[j]) { if (found) return false; found = true; if (t.size() > s.size()) { i--; } } } return (found || t.size() > s.size()); } };
相关文章推荐
- #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]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-One Edit Distance
- LeetCode - One Edit Distance
- [LeetCode161] One Edit Distance
- leetcode - One Edit Distance
- leetcode 161: One Edit Distance
- [LeetCode] One Edit Distance
- leetcode[161] One Edit Distance