Leetcode 面试题 01.05. 一次编辑(DAY 53) ---- 动态规划学习期 (心头鬼火冒 测试数据出现问题 我真麻了)

原题题目

面试题 01.05. 一次编辑



代码实现(首刷自解)

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;
}


测试数据截图(我真麻了)

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_37500516/article/details/114074095