Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created February 5, 2017 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/f75daa6055d7f0cb448b5248367551fc to your computer and use it in GitHub Desktop.
Save jianminchen/f75daa6055d7f0cb448b5248367551fc to your computer and use it in GitHub Desktop.
Hashfunction - design a hash function for Leetcode 49
int Fun(string s, int l, int r)
{
var ret = new int[26];
for (int i = l; i <= r; i++)
ret[s[i] - 'a']++;
int x = 0; // Julia's comment: should be 1
for (int i = 0; i < 26; i++)
x = x * 701 + ret[i];
return x;
}
@ArashPartow
Copy link

A comprehensive list of general purpose hash functions and their implementations can found here:

https://www.partow.net/programming/hashfunctions/index.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment