原题题目
代码实现(首刷自解)
bool oneEditAway(char* first, char* second){
int i,flag = 1,strl1 = strlen(first),strl2 = strlen(second),pos1 = 0,pos2 = 0;
if(strl1 >= strl2 + 2 || strl2 >= strl1 + 2) return false;
for(i=0;i<strl1;i++)
{
if(i == strl1-1)
{
if(flag || first[pos1] == second[pos2] && pos2 == strl2-1 || sizeof(strl2) != strl2 && first[pos1] == second[pos2] && pos2 == sizeof(strl2) -1 ) return true;
else return false;
}
if(first[pos1] != second[pos2])
{
if(!flag) return false;
if(first[pos1] == second[pos2+1]) pos2++;
else if(first[pos1+1] == second[pos2]) pos1++;
else if(first[pos1+1] == second[pos2+1]) flag = 0;
else return false;
flag = 0;
}
pos1++;
pos2++;
}
return true;
}
测试数据截图(我真麻了)