Avatar

Organizations

12 results for 哈希表
  • 字典  wordList 中从单词 beginWordendWord转换序列是一个按下述规格形成的序列

    \(beginWord \to s_1 \to s_2 \to \dots \to s_k\):

    • 每一对相邻的单词只差一个字母。
    • 对于  1 <= i <= k  时,每个 \(s_i\)  都在wordList  中。注意, beginWord 不需要在wordList  中。
    • \(s_k == endWord\)

    给你两个单词 beginWordendWord 和一个字典 wordList ,返回从  beginWord 到  endWord最短转换序列中的单词数目。如果不存在这样的转换序列,返回 0

  • 给你一个未排序的整数数组 nums ,请你找出其中没有出现的最小的正整数。

    leetcode 困难 数组 哈希表 Created Fri, 23 Sep 2022 12:33:32 +0800
  • 给你一个字符串 s 、一个字符串 t 。返回 s 中涵盖 t 所有字符的最小子串。如果 s 中不存在涵盖 t 所有字符的子串,则返回空字符串 ""

  • Given an array of integers nums and an integer k, return the total number of subarrays whose sum equals to k.

    A subarray is a contiguous non-empty sequence of elements within an array.

    leetcode 中等 数组 哈希表 前缀和 Created Mon, 27 Jun 2022 14:37:09 +0800
  • Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.

    If the fractional part is repeating, enclose the repeating part in parentheses.

    If multiple answers are possible, return any of them.

    It is guaranteed that the length of the answer string is less than 104 for all the given inputs.

    leetcode 中等 哈希表 数学 字符串 Created Tue, 21 Jun 2022 15:53:27 +0800
  • 实现RandomizedSet 类:

    • RandomizedSet() 初始化 RandomizedSet 对象
    • bool insert(int val) 当元素 val 不存在时,向集合中插入该项,并返回 true ;否则,返回 false
    • bool remove(int val) 当元素 val 存在时,从集合中移除该项,并返回 true ;否则,返回 false
    • int getRandom() 随机返回现有集合中的一项(测试用例保证调用此方法时集合中至少存在一个元素)。每个元素应该有 相同的概率 被返回。

    你必须实现类的所有函数,并满足每个函数的 平均 时间复杂度为 O(1)

    leetcode 中等 设计 数组 哈希表 Created Wed, 13 Apr 2022 15:22:28 +0800
  • You are given a character array keys containing unique characters and a string array values containing strings of length 2. You are also given another string array dictionary that contains all permitted original strings after decryption. You should implement a data structure that can encrypt or decrypt a 0-indexed string.

    A string is encrypted with the following process:

    1. For each character c in the string, we find the index i satisfying keys[i] == c in keys.
    2. Replace c with values[i] in the string.

    A string is decrypted with the following process:

    1. For each substring s of length 2 occurring at an even index in the string, we find an i such that values[i] == s. If there are multiple valid i, we choose any one of them. This means a string could have multiple possible strings it can decrypt to.
    2. Replace s with keys[i] in the string.

    Implement the Encrypter class:

    • Encrypter(char[] keys, String[] values, String[] dictionary) Initializes the Encrypter class with keys, values, and dictionary.
    • String encrypt(String word1) Encrypts word1 with the encryption process described above and returns the encrypted string.
    • int decrypt(String word2) Returns the number of possible strings word2 could decrypt to that also appear in dictionary.
    leetcode 困难 字符串 哈希表 Created Sun, 03 Apr 2022 17:10:49 +0800
  • 当一个字符串 s  包含的每一种字母的大写和小写形式 同时  出现在 s  中,就称这个字符串  s  是 美好 字符串。比方说,"abABB"  是美好字符串,因为  'A' 和  'a'  同时出现了,且  'B' 和  'b'  也同时出现了。然而,"abA"  不是美好字符串因为  'b'  出现了,而  'B'  没有出现。

    给你一个字符串  s ,请你返回  s  最长的  美好子字符串 。如果有多个答案,请你返回  最早  出现的一个。如果不存在美好子字符串,请你返回一个空字符串。

    leetcode 简单 位运算 哈希表 字符串 Created Tue, 01 Feb 2022 19:52:49 +0800
  • 农夫约翰的 N 头奶牛站在一维长围栏的不同位置。

    第 i 头牛位于位置 xi,其所属品种为 bi(根西岛牛或荷斯坦牛)。

    所有奶牛的位置各不相同。

    约翰想给一段连续区间内的奶牛拍摄一张照片,用来在乡村集市上展览。

    但是我们希望他所有品种的奶牛都能在照片中得到公平的展示。

    因此,他希望确保无论照片中出些哪些品种的奶牛,每种品种的奶牛在照片中的数量都必须相等。

    例如,一张照片中只包含荷斯坦牛是可以的,包含荷斯坦牛和根西岛牛各 27 头也没问题,但是包含 10 头荷斯坦牛和 9 头根西岛牛则不可以。

    请确定,约翰可以拍下的满足以上条件的照片的最大尺寸。

    照片的尺寸是指照片中奶牛最大和最小位置之间的差。

    约翰最终可能只拍下一头奶牛,这种情况下,照片尺寸为 0。

    acwing 简单 枚举 前缀和 哈希表 Created Thu, 20 Jan 2022 12:57:54 +0800
  • 在一个 \(10^6 \times 10^6\) 的网格中,每个网格上方格的坐标为 (x, y)

    现在从源方格 \(source = [s_x, s_y]\) 开始出发,意图赶往目标方格 \(target = [t_x, t_y]\) 。数组 blocked 是封锁的方格列表,其中每个 \(blocked[i] = [x_i, y_i]\) 表示坐标为 \((x_i, y_i)\) 的方格是禁止通行的。

    每次移动,都可以走到网格中在四个方向上相邻的方格,只要该方格 在给出的封锁列表 blocked 上。同时,不允许走出网格。

    只有在可以通过一系列的移动从源方格 source 到达目标方格 target 时才返回 true。否则,返回 false

Next