mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-12-19 02:24:59 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>给定整数 <code>p</code> 和 <code>m</code> ,一个长度为 <code>k</code> 且下标从 <strong>0</strong> 开始的字符串 <code>s</code> 的哈希值按照如下函数计算:</p>\n\n<ul>\n\t<li><code>hash(s, p, m) = (val(s[0]) * p<sup>0</sup> + val(s[1]) * p<sup>1</sup> + ... + val(s[k-1]) * p<sup>k-1</sup>) mod m</code>.</li>\n</ul>\n\n<p>其中 <code>val(s[i])</code> 表示 <code>s[i]</code> 在字母表中的下标,从 <code>val('a') = 1</code> 到 <code>val('z') = 26</code> 。</p>\n\n<p>给你一个字符串 <code>s</code> 和整数 <code>power</code>,<code>modulo</code>,<code>k</code> 和 <code>hashValue</code> 。请你返回 <code>s</code> 中 <strong>第一个</strong> 长度为 <code>k</code> 的 <strong>子串</strong> <code>sub</code> ,满足<em> </em><code>hash(sub, power, modulo) == hashValue</code> 。</p>\n\n<p>测试数据保证一定 <strong>存在</strong> 至少一个这样的子串。</p>\n\n<p><strong>子串</strong> 定义为一个字符串中连续非空字符组成的序列。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre><b>输入:</b>s = \"leetcode\", power = 7, modulo = 20, k = 2, hashValue = 0\n<strong>输出:</strong>\"ee\"\n<strong>解释:</strong>\"ee\" 的哈希值为 hash(\"ee\", 7, 20) = (5 * 1 + 5 * 7) mod 20 = 40 mod 20 = 0 。\n\"ee\" 是长度为 2 的第一个哈希值为 0 的子串,所以我们返回 \"ee\" 。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre><b>输入:</b>s = \"fbxzaad\", power = 31, modulo = 100, k = 3, hashValue = 32\n<b>输出:</b>\"fbx\"\n<b>解释:</b>\"fbx\" 的哈希值为 hash(\"fbx\", 31, 100) = (6 * 1 + 2 * 31 + 24 * 31<sup>2</sup>) mod 100 = 23132 mod 100 = 32 。\n\"bxz\" 的哈希值为 hash(\"bxz\", 31, 100) = (2 * 1 + 24 * 31 + 26 * 31<sup>2</sup>) mod 100 = 25732 mod 100 = 32 。\n\"fbx\" 是长度为 3 的第一个哈希值为 32 的子串,所以我们返回 \"fbx\" 。\n注意,\"bxz\" 的哈希值也为 32 ,但是它在字符串中比 \"fbx\" 更晚出现。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= k <= s.length <= 2 * 10<sup>4</sup></code></li>\n\t<li><code>1 <= power, modulo <= 10<sup>9</sup></code></li>\n\t<li><code>0 <= hashValue < modulo</code></li>\n\t<li><code>s</code> 只包含小写英文字母。</li>\n\t<li>测试数据保证一定 <strong>存在</strong> 满足条件的子串。</li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 30,
|
||||
"likes": 31,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -155,7 +155,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"4.3K\", \"totalSubmission\": \"18.1K\", \"totalAcceptedRaw\": 4309, \"totalSubmissionRaw\": 18066, \"acRate\": \"23.9%\"}",
|
||||
"stats": "{\"totalAccepted\": \"4.5K\", \"totalSubmission\": \"18.8K\", \"totalAcceptedRaw\": 4525, \"totalSubmissionRaw\": 18783, \"acRate\": \"24.1%\"}",
|
||||
"hints": [
|
||||
"How can we update the hash value efficiently while iterating instead of recalculating it each time?",
|
||||
"Use the rolling hash method."
|
||||
|
||||
Reference in New Issue
Block a user