首页 > 其他 > 详细

one edit distance

时间:2014-11-23 17:10:21      阅读:175      评论:0      收藏:0      [点我收藏+]
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");
}

 

one edit distance

原文:http://www.cnblogs.com/jobfindingnotes/p/4116627.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!