题库chevron_right分类chevron_right哈希函数
label

哈希函数

31 道题目
简单: 4中等: 10困难: 17

哈希函数 是技术面试里最常出现的能力维度之一。建议先掌握基础题型的边界处理,再逐步过渡到模式识别和复杂度 trade-off。

面试场景

高频考察问题建模、边界条件与口头表达的清晰度。

常见误区

只背模板不解释为什么,容易在追问里失分。

练习策略

每轮练 3-5 题,固定复盘复杂度和可替代解法。

推荐练习顺序

#题目难度
187

重复的DNA序列

Solve Repeated DNA Sequences by sliding a length-10 window and tracking seen patterns with a hash set or bitmask.

中等
214

最短回文串

The Shortest Palindrome problem asks to transform a string into a palindrome by adding characters at the beginning, with…

困难
535

TinyURL 的加密与解密

Design a class that encodes and decodes URLs using a URL shortening approach based on hash tables and strings.

中等
572

另一棵树的子树

Determine if one binary tree is an exact subtree of another by comparing structure and node values recursively.

简单
705

设计哈希集合

Implement a custom HashSet without built-in libraries using array scanning and hash lookup for efficient membership chec…

简单
706

设计哈希映射

Implement a custom HashMap from scratch using array scanning and hash lookup without built-in libraries for efficient ke…

简单
718

最长重复子数组

Find the maximum length of a subarray that appears in both given integer arrays using dynamic programming.

中等
1044

最长重复子串

Find the longest duplicated substring in a string using binary search, sliding window, and rolling hash techniques.

困难
1147

段式回文

Solve the "Longest Chunked Palindrome Decomposition" problem by using dynamic programming and string manipulation techni…

困难
1316

不同的循环子字符串

Count the distinct non-empty substrings of a given string that can be formed as the concatenation of a string with itsel…

困难
1392

最长快乐前缀

Find the longest non-empty prefix of a string that also appears as its suffix, optimizing with rolling hash techniques.

困难
1461

检查一个字符串是否包含所有长度为 K 的二进制子串

Determine if every possible binary string of length k exists as a substring within a given binary string s efficiently u…

中等
1923

最长公共子路径

The Longest Common Subpath problem requires finding the longest subpath shared by all paths in a graph using binary sear…

困难
1948

删除系统中的重复文件夹

Solve Delete Duplicate Folders in System by building a trie, serializing child subtrees, and deleting repeated non-empty…

困难
1960

两个回文子字符串长度的最大乘积

Find the maximum product of lengths of two non-overlapping odd-length palindromic substrings using string and rolling ha…

困难
2156

查找给定哈希值的子串

Locate the first substring of length k whose rolling hash matches the given hashValue using a sliding window approach.

困难
2223

构造字符串的总得分和

Calculate the sum of scores of built strings by analyzing longest common prefixes with suffixes in a string using effici…

困难
2261

含最多 K 个可整除元素的子数组

Count all distinct subarrays with at most k elements divisible by p using array scanning and hash lookup techniques effi…

中等
2430

对字母串可执行的最大删除数

Find the maximum number of deletions on a string using state transition dynamic programming and rolling hash techniques …

困难
3006

找出数组中的美丽下标 I

Identify all beautiful indices where substring a appears and a nearby substring b exists within distance k efficiently.

中等
3008

找出数组中的美丽下标 II

Find Beautiful Indices in the Given Array II challenges you to use binary search and string matching techniques.

困难
3029

将单词恢复初始状态所需的最短时间 I

Determine the minimum seconds to revert a string to its original state using repeated prefix shifts of length k efficien…

中等
3031

将单词恢复初始状态所需的最短时间 II

The problem asks to calculate the minimum time required to revert a string to its initial state using specific operation…

困难
3034

匹配模式数组的子数组数目 I

Count all subarrays in a given integer array that strictly follow a defined numeric pattern using rolling hash checks ef…

中等
3036

匹配模式数组的子数组数目 II

Count subarrays matching a pattern of relative values using array transformation and rolling hash techniques.

困难
3042

统计前后缀下标对 I

Count all index pairs where one word is both a prefix and suffix of another, using efficient array and string checks.

简单
3045

统计前后缀下标对 II

Count the number of index pairs in a string array where one word is both a prefix and suffix of another using array and …

困难
3291

形成目标字符串需要的最少字符串数 I

Use dynamic programming to split target into the fewest prefixes that match any word prefix, while ruling out dead posit…

中等
3292

形成目标字符串需要的最少字符串数 II

Compute the minimum number of valid strings from an array needed to construct a given target string efficiently using dy…

困难
3327

判断 DFS 字符串是否是回文串

Determine if strings formed by DFS traversal of a tree are palindromes using array scanning and hash lookups efficiently…

困难
3529

统计水平子串和垂直子串重叠格子的数目

Efficiently count grid cells appearing in both horizontal and vertical occurrences of a given string pattern using array…

中等

关联高频模式

LeetCode 哈希函数题型题解:31题训练路线