兩個字串的hashCode相同但這兩個字串不相等的情況
阿新 • • 發佈:2022-04-14
public int hashCode() { int h = hash; if (h == 0 && value.length > 0) { char val[] = value; for (int i = 0; i < value.length; i++) { h = 31 * h + val[i]; } hash = h; }return h; }
可知
str.charAt(0) * 31^(n-1) + str.charAt(1) * 31^(n-2) + ... + str.charAt(n-1)
那我們最簡單的操作就是當n=2的時候
x1*31 + x2 = y1*31 + y2
可得(x1-y1) * 31 = y2 - x2;
大家可以去查查Ascii表中的Ascii碼 找出x1,x2與y1,y2滿足上面式子的情況
我這邊找到的是"3C"與"2b"
轉載:https://blog.csdn.net/Cia_zibo/article/details/104870197
TRANSLATE with