Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- bool isOneEditDistance(string s, string t) {
- int m = s.size(), n = t.size();
- for (int i = 0; i < min(m, n); i++) {
- if(s[i] != t[i]){
- if(m == n) // Replace char.
- return s.substr(i + 1) == t.substr(i + 1);
- else if(m > n) // Delete char.
- return s.substr(i+1) == t.substr(i);
- else // Insert char.
- return s.substr(i) == t.substr(i+1);
- }
- }
- return abs(m-n) == 1;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment