Created
February 5, 2017 18:27
-
-
Save jianminchen/f75daa6055d7f0cb448b5248367551fc to your computer and use it in GitHub Desktop.
Hashfunction - design a hash function for Leetcode 49
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A comprehensive list of general purpose hash functions and their implementations can found here:
https://www.partow.net/programming/hashfunctions/index.html