我输入(“ubuntu”,1007)的时候,我的结果被显示错误。
class Solution {
/**
* @param key: A String you should hash
* @param HASH_SIZE: An integer
* @return an integer
*/
public int hashCode(char[] key,int HASH_SIZE) {
// write your code here
int q=1;
long result=0;
int len=key.length;
for(int i=len-1;i>-1;i--)
{
result=result+key[i]*q;
q=q*33;
}
result= result % HASH_SIZE;
return (int) result;
}
};