![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
哈希
文章平均质量分 83
memcpy0
希望探索文理结合的自由之路。
展开
-
LeetCode 572. 另一棵树的子树【树+嵌套DFS;DFS序+KMP;树哈希】简单【C++,Java,GO】
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。。原创 2024-08-11 23:21:20 · 195 阅读 · 0 评论 -
LeetCode 1326. Minimum Number of Taps to Open to Water a Garden【贪心,桶排序】
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。为了方便在PC上运行调试、分享代码文件,我还建立了相关的。原创 2023-03-01 19:36:25 · 353 阅读 · 0 评论 -
LeetCode 2347. Best Poker Hand【哈希表,计数】
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。为了方便在PC上运行调试、分享代码文件,我还建立了相关的。原创 2023-03-01 03:45:42 · 37 阅读 · 0 评论 -
LeetCode 2206. Divide Array Into Equal Pairs【数组/哈希】简单
You are given an integer array nums consisting of 2 * n integers.You need to divide nums into n pairs such that: Each element belongs to exactly one pair. The elements present in a pair are equal.Return true if nums can be divided into n pairs, other原创 2022-03-21 20:13:58 · 473 阅读 · 0 评论 -
LeetCode 187. Repeated DNA Sequences【哈希表/滑动窗口/字符串哈希/滚动哈希/位操作】中等
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。为了方便在PC上运行调试、分享代码文件,我还建立了相关的仓库:https://github.com/memcpy0/LeetCode-Conqu.原创 2021-10-09 00:21:44 · 255 阅读 · 0 评论 -
CCF 202104-1 灰度直方图【哈希计数】
问题描述一幅长宽分别为 nnn 个像素和 mmm 个像素的灰度图像可以表示为一个 n×mn \times mn×m 大小的矩阵 AAA 。其中每个元素 AijA_{ij}Aij (0≤i<n0\le i \lt n0≤i<n、0≤j<m0\le j \lt m0≤j<m)是一个 [0,L)[0, L)[0,L) 范围内的整数,表示对应位置像素的灰度值。具体来说,一个 888 比特的灰度图像中每个像素的灰度范围是 [0,128)[0, 128)[0,128) 。一副灰度图像的灰原创 2021-08-31 23:04:27 · 252 阅读 · 0 评论 -
LeetCode C++ 13. Roman to Integer【String/Hash Table】简单
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D 500M 1000For example, 2 is writt原创 2021-05-16 02:16:03 · 174 阅读 · 0 评论 -
LeetCode C++ 12. Integer to Roman【Greedy/Hash Table】中等
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D 500M 1000For example, 2 is writt原创 2021-05-16 02:00:57 · 161 阅读 · 0 评论 -
LeetCode C++ 554. Brick Wall【哈希表/前缀和】中等
There is a rectangular brick wall in front of you with n rows of bricks. The ith row has some number of bricks each of the same height (i.e., one unit) but they can be of different widths. The total width of each row is the same.Draw a vertical line from原创 2021-05-07 00:24:45 · 195 阅读 · 0 评论 -
LeetCode C++ 987. Vertical Order Traversal of a Binary Tree【Tree/BFS/DFS/Hash Table】困难
Given the root of a binary tree, calculate the vertical order traversal of the binary tree.For each node at position (row, col), its left and right children will be at positions (row + 1, col - 1) and (row + 1, col + 1) respectively. The root of the tree原创 2021-02-16 00:26:32 · 168 阅读 · 0 评论 -
LeetCode C++ 765. Couples Holding Hands【Array/Hash Table】困难
N couples sit in 2N seats arranged in a row and want to hold hands. We want to know the minimum number of swaps so that every couple is sitting side by side. A swap consists of choosing any two people, then they stand up and switch seats. The people a.原创 2021-02-15 09:47:00 · 206 阅读 · 0 评论 -
LeetCode C++ 448. Find All Numbers Disappeared in an Array【Array/Hash Table】简单
6-10 阶乘计算升级版 (20分)本题要求实现一个打印非负整数阶乘的函数。函数接口定义:void Print_Factorial ( const int N );其中N是用户传入的参数,其值不超过1000。如果N是非负整数,则该函数必须在一行中打印出N!的值,否则打印“Invalid input”。裁判测试程序样例:#include <stdio.h>void Pr...原创 2020-02-14 12:43:31 · 252 阅读 · 0 评论 -
LeetCode 面试题 17.05. Find Longest Subarray LCCI【哈希表/前缀和】中等
Given an array filled with letters and numbers, find the longest subarray with an equal number of letters and numbers.Return the subarray. If there are more than one answer, return the one which has the smallest index of its left endpoint. If there i原创 2021-01-06 00:20:45 · 247 阅读 · 0 评论 -
LeetCode C++ 面试题 17.11. Find Closest LCCI【Two Pointers/Hash Table】中等
You have a large text file containing words. Given any two words, find the shortest distance (in terms of number of words) between them in the file. If the operation will be repeated many times for the same file (but different pairs of words), can you opti原创 2021-01-05 23:57:30 · 235 阅读 · 0 评论 -
LeetCode C++ 819. Most Common Word【String/Hash Table】简单
Given a paragraph and a list of banned words, return the most frequent word that is not in the list of banned words. It is guaranteed there is at least one word that isn't banned, and that the answer is unique.Words in the list of banned words原创 2020-12-24 00:09:16 · 203 阅读 · 0 评论 -
LeetCode C++ 387. First Unique Character in a String【String/Hash Table】简单
Given a string, find the first non-repeating character in it and return its index. If it doesn’t exist, return -1.Examples:s = "leetcode"return 0.s = "loveleetcode"return 2.Note: You may assume the string contains only lowercase English letters.题意原创 2020-12-23 16:48:56 · 181 阅读 · 0 评论 -
LeetCode C++ 1426. Counting Elements【Array/Hash Table】简单
Given an integer array arr, count how many elements x there are, such that x + 1 is also in arr.If there’re duplicates in arr, count them seperately.Example 1:Input: arr = [1,2,3]Output: 2Explanation: 1 and 2 are counted cause 2 and 3 are in arr.Exa原创 2020-12-19 13:17:05 · 187 阅读 · 1 评论 -
LeetCode 389. Find the Difference【哈希表/位运算】简单
Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter at a random position.Find the letter that was added in t.Example:Input:s = "abcd"t = "abcde"Output:e原创 2020-06-27 22:08:57 · 240 阅读 · 0 评论 -
LeetCode C++ 1165. Single-Row Keyboard【String/Hash Table】简单
There is a special keyboard with all keys in a single row.Given a string keyboard of length 26 indicating the layout of the keyboard (indexed from 0 to 25), initially your finger is at index 0. To type a character, you have to move your finger to the原创 2020-12-18 18:00:53 · 226 阅读 · 1 评论 -
LeetCode C++ 1133. Largest Unique Number【Hash Table】简单
Given an array of integers A , return the largest integer that only occurs once. If no integer occurs once, return -1 .Example 1:Input: [5,7,3,9,4,9,8,3,1]Output: 8Explanation: The maximum integer in the array is 9 but it is repeated. The number 8 occ原创 2020-12-18 17:22:32 · 184 阅读 · 1 评论 -
LeetCode C++ 1118. Number of Days in a Month【Hash Table】简单
Given a year Y and a month M, return how many days there are in that month.Example 1:Input: Y = 1992, M = 7Output: 31Example 2:Input: Y = 2000, M = 2Output: 29Example 3:Input: Y = 1900, M = 2Output: 28Note:1583 <= Y <= 21001 <= M &原创 2020-12-18 17:02:40 · 176 阅读 · 1 评论 -
LeetCode C++ 49. Group Anagrams【Hash Table/String】中等
Given an array of strings strs, group the anagrams together. You can return the answer in any order.An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.Exam原创 2020-12-14 00:46:57 · 170 阅读 · 0 评论 -
LeetCode C++ 217. Contains Duplicate【Array/Hash Table】简单
Given an array of integers, find if the array contains any duplicates.Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.Example 1:Input: [1,2,3,1]Output: trueExa原创 2020-12-13 23:58:06 · 185 阅读 · 0 评论 -
LeetCode C++ 1497. Check If Array Pairs Are Divisible by k【Math/Hash Table】中等
Given an array of integers arr of even length n and an integer k.We want to divide the array into exactly n / 2 pairs such that the sum of each pair is divisible by k.Return True If you can find a way to do that or False otherwise.Example 1:Input:原创 2020-12-08 01:21:50 · 255 阅读 · 0 评论 -
LeetCode C++ 204. Count Primes【Math/Hash Table】简单
Count the number of prime numbers less than a non-negative number, n.Example 1:Input: n = 10Output: 4Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.Example 2:Input: n = 0Output: 0Example 3:Input: n = 1Output: 0Constr原创 2020-12-03 01:38:28 · 313 阅读 · 0 评论 -
LeetCode C++ 454. 4Sum II【Hash Table/Sort/Two Pointers/Binary Search】中等
Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero.To make problem a bit easier, all A, B, C, D have same length of N where 0 ≤ N ≤ 500. All integers are in the range o原创 2020-11-28 14:27:10 · 299 阅读 · 0 评论 -
LeetCode C++ 1370. Increasing Decreasing String【String/Hash Table】简单
Given a string s. You should re-order the string using the following algorithm:Pick the smallest character from s and append it to the result.Pick the smallest character from s which is greater than the last appended character to the result and append i原创 2020-11-25 01:18:37 · 147 阅读 · 0 评论 -
LeetCode C++ 888. Fair Candy Swap【Array/Hash Table】简单
Alice and Bob have candy bars of different sizes: A[i] is the size of the i-th bar of candy that Alice has, and B[j] is the size of the j-th bar of candy that Bob has.Since they are friends, they would like to exchange one candy bar each so that after the原创 2020-11-14 10:06:18 · 159 阅读 · 0 评论 -
LeetCode 1436. Destination City【哈希表/字符串】简单
You are given the array paths, where paths[i] = [cityAi, cityBi] means there exists a direct path going from cityAi to cityBi. Return the destination city, that is, the city without any path outgoing to another city.It is guaranteed that the graph of path原创 2020-11-12 11:58:29 · 293 阅读 · 0 评论 -
LeetCode C++ 599. Minimum Index Sum of Two Lists【Hash Table】简单
Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings.You need to help them find out their common interest with the least list index sum. If there is a choice tie between an原创 2020-11-11 19:34:10 · 150 阅读 · 0 评论 -
LeetCode C++ 594. Longest Harmonious Subsequence【HashTable/Sort/Two Pointers/Sliding Window】简单
We define a harmonious array as an array where the difference between its maximum value and its minimum value is exactly 1 .Given an integer array nums, return the length of its longest harmonious subsequence among all its possible subsequences.A subsequ原创 2020-11-10 20:45:27 · 145 阅读 · 0 评论 -
LeetCode C++ 697. Degree of an Array【Array/Hash Table】简单
Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.Your task is to find the smallest possible length of a (contiguous) subarray of nums, that has the same degree a原创 2020-11-08 23:35:56 · 157 阅读 · 0 评论 -
LeetCode C++ 128. Longest Consecutive Sequence【Sort/Hash Table】困难
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.Your algorithm should run in O(n) complexity.Example:Input: [100, 4, 200, 1, 3, 2]Output: 4Explanation: The longest consecutive elements sequence is [1,原创 2020-06-06 13:42:45 · 205 阅读 · 0 评论 -
Leetcode C++ 349. Intersection of Two Arrays【Hash Table/Sort/Two Pointers/Binary Search】简单
Given two arrays, write a function to compute their intersection.Example 1:Input: nums1 = [1,2,2,1], nums2 = [2,2]Output: [2]Example 2:Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4]Output: [9,4]...原创 2020-03-28 01:11:24 · 200 阅读 · 0 评论 -
LeetCode C++ 383. Ransom Note【String/Hash Table】简单
Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; otherwise, it will return false.Each letter in the magazi原创 2020-10-28 13:33:49 · 215 阅读 · 0 评论 -
LeetCode C++ 1207. Unique Number of Occurrences【Hash Table】简单
Given an array of integers arr, write a function that returns true if and only if the number of occurrences of each value in the array is unique.Example 1:Input: arr = [1,2,2,1,1,3]Output: trueExplanation: The value 1 has 3 occurrences, 2 has 2 and 3 h原创 2020-10-28 00:58:20 · 157 阅读 · 0 评论 -
LeetCode C++ 面试题 16.15. Master Mind LCCI【Hash Table】简单
The Game of Master Mind is played as follows:The computer has four slots, and each slot will contain a ball that is red ®. yellow (Y). green (G) or blue (B). For example, the computer might have RGGB (Slot #1 is red, Slots #2 and #3 are green, Slot #4 is原创 2020-10-28 00:06:31 · 241 阅读 · 0 评论 -
LeetCode C++ 409. Longest Palindrome【String/Hash Table】简单
Given a string s which consists of lowercase or uppercase letters, return the length of the longest palindrome that can be built with those letters.Letters are case sensitive, for example, "Aa" is not considered a palindrome here.Example 1:Input: s = "a原创 2020-10-03 11:32:43 · 178 阅读 · 0 评论 -
LeetCode C++ 645. Set Mismatch【Hash Table/Bit Manipulation/Math】简单
The set S originally contains numbers from 1 to n. But unfortunately, due to the data error, one of the numbers in the set got duplicated to another number in the set, which results in repetition of one number and loss of another number.Given an array num原创 2020-10-03 10:15:02 · 196 阅读 · 0 评论 -
LeetCode 771. Jewels and Stones【哈希表,状态压缩】简单
You’re given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You want to know how many of the stones you have are also jewels.The letters in J are guara原创 2020-10-02 11:35:52 · 165 阅读 · 0 评论