class Solution {
public:
bool oneEditAway(std::string first, std::string second) {
int m = first.length(), n = second.length();
if (m < n) {
return oneEditAway(second, first);
}
if (m - n > 1) {
return false;
}
int cnt = 0;
if (m == n) {
for (int i = 0; i < n; ++i) {
if (first[i] != second[i]) {
if (++cnt > 1) {
return false;
}
}
}
return true;
}
for (int i = 0, j = 0; i < m; ++i) {
if (j == n || (j < n && first[i] != second[j])) {
++cnt;
} else {
++j;
}
}
return cnt < 2;
}
};