strStr

作者: 6默默Welsh | 来源:发表于2018-05-08 17:11 被阅读23次

    594.strStr II
    思路
    分别求出 target 和 source 中对应长度的字符串的 hashcode,二者hashcode 相等时比较两段字符串是否相同
    错误

    1. hash 函数书写不熟练
      targetCode = (targetCode * 31 + target.charAt(i)) % base;
      hashCode = (hashCode * 31 + source.charAt(j)) % base;
      hashCode = hashCode - (source.charAt(j - m) * power) % base;
    2. 字符串的比较忘记怎么写
      source.substring(j - m + 1, j + 1).equals(target)

    相关文章

      网友评论

          本文标题:strStr

          本文链接:https://www.haomeiwen.com/subject/ivswrftx.html