strStr

2018-05-08  本文已影响23人  6默默Welsh

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)
上一篇 下一篇

猜你喜欢

热点阅读