bool oneDistance(string s1, string s2) { if (s1.length()<s2.length()) { swap(s1, s2); } if (s1.length() - s2.length() >1) return false; bool replace = true; if (s1.length() != s2.length()) { replace = false; } int times = 0; for (int i = 0, j = 0; j < s1.length();) { if (i == s2.length() || s1[j] != s2[i]) { times += 1; if (times>1) return false; if (replace) { continue; } else { ++j; } } else { ++i; ++j; } } return true; } int main() { auto r = oneDistance("atc", "at"); }
时间: 2024-10-21 01:07:30