problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::find_substring_with_given_hash_value::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static string subStrHash (string s, int power, int modulo, int k, int hashValue)
 

详细描述

在文件 leetcode.h820 行定义.

成员函数说明

◆ subStrHash()

string leetcode::find_substring_with_given_hash_value::Solution::subStrHash ( string  s,
int  power,
int  modulo,
int  k,
int  hashValue 
)
static

在文件 leetcode.cpp1980 行定义.

1980 {
1981 power %= modulo;
1982 auto *const pn = new int[k];
1983 pn[0] = 1;
1984 for(int i = 1; i < k; i++) {
1985 pn[i] = static_cast<unsigned long long>(pn[i - 1]) * static_cast<unsigned long long>(power) % modulo;
1986 }
1987
1988 for(int i = 0; i < s.length(); i++) {
1989 unsigned long long hash = 0;
1990 for(int j = 0; j < k; j++) {
1991 hash += static_cast<unsigned long long>((s[i + j] - 'a' + 1) % modulo) * pn[j];
1992 hash %= modulo;
1993 }
1994 if(hash == hashValue) {
1995 return s.substr(i, k);
1996 }
1997 }
1998 delete[] pn;
1999 return "";
2000 }

被这些函数引用 leetcode::find_substring_with_given_hash_value::TEST().


该类的文档由以下文件生成: