| 38 | } |
| 39 | |
| 40 | unsigned long getHash(string str) { |
| 41 | int cnt[26] = {0}; |
| 42 | for (char c : str) { |
| 43 | cnt[c - 'a'] ++ ; |
| 44 | } |
| 45 | unsigned long res = 0; |
| 46 | for (int i = 0; i < 26; i++) { |
| 47 | res += cnt[i] * pow(prime, i); |
| 48 | } |
| 49 | return res; |
| 50 | } |
| 51 | |
| 52 | |
| 53 | // O(1) |