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) {
// 2015-09-04
if (key == null || key.length == 0 || HASH_SIZE == 0) {
return -1;
}
long result = 0;
for (int i = 0; i < key.length; i++) {
result = result * 33 + (int)key[i];
result %= HASH_SIZE;
}
return (int)result;
}
};
[刷题]Hash Function
最新推荐文章于 2023-04-23 20:59:42 发布