directory
0.0.0-20240920062246-d0657495930a
Repository: https://github.com/yigmmk/leetcode.git
Documentation: pkg.go.dev

# Packages

@lc code=start* * Definition for a binary tree node.
@lc code=start* * Definition for a binary tree node.
@lc code=start* * Definition for a binary tree node.
No description provided by the author
@lc code=start* * Definition for a binary tree node.
No description provided by the author
* @lc app=leetcode.cn id=208 lang=golang * * [208] 实现 Trie (前缀树) * * https://leetcode.cn/problems/implement-trie-prefix-tree/description/ * - algorithms - Medium (71.91%) - Likes: 1219 - Dislikes: 0 - Total Accepted: 208.6K - Total Submissions: 290K - Testcase Example: '["Trie","insert","search","search","startsWith","insert","search"]\n' + '[[],["apple"],["apple"],["app"],["app"],["app"],["app"]]' * * Trie(发音类似 "try")或者说 前缀树 * 是一种树形数据结构,用于高效地存储和检索字符串数据集中的键。这一数据结构有相当多的应用情景,例如自动补完和拼写检查。 * * 请你实现 Trie 类: * * * Trie() 初始化前缀树对象。 * void insert(String word) 向前缀树中插入字符串 word 。 * boolean search(String word) 如果字符串 word 在前缀树中,返回 true(即,在检索之前已经插入);否则,返回 * false 。 * boolean startsWith(String prefix) 如果之前已经插入的字符串 word 的前缀之一为 prefix ,返回 true * ;否则,返回 false 。 * * * * * 示例: * * * 输入 * ["Trie", "insert", "search", "search", "startsWith", "insert", "search"] * [[], ["apple"], ["apple"], ["app"], ["app"], ["app"], ["app"]] * 输出 * [null, null, true, false, true, null, true] * * 解释 * Trie trie = new Trie(); * trie.insert("apple"); * trie.search("apple"); // 返回 True * trie.search("app"); // 返回 False * trie.startsWith("app"); // 返回 True * trie.insert("app"); * trie.search("app"); // 返回 True * * * * * 提示: * * * 1 * word 和 prefix 仅由小写英文字母组成 * insert、search 和 startsWith 调用次数 总计 不超过 3 * 10^4 次 * * */.
No description provided by the author
No description provided by the author
No description provided by the author
* @lc app=leetcode.cn id=677 lang=golang * * [677] 键值映射 * * https://leetcode.cn/problems/map-sum-pairs/description/ * - algorithms - Medium (66.38%) - Likes: 214 - Dislikes: 0 - Total Accepted: 42.4K - Total Submissions: 64K - Testcase Example: '["MapSum","insert","sum","insert","sum"]\n' + '[[],["apple",3],["ap"],["app",2],["ap"]]' * * 设计一个 map ,满足以下几点: * * * 字符串表示键,整数表示值 * 返回具有前缀等于给定字符串的键的值的总和 * * * 实现一个 MapSum 类: * * * MapSum() 初始化 MapSum 对象 * void insert(String key, int val) 插入 key-val 键值对,字符串表示键 key ,整数表示值 val 。如果键 * key 已经存在,那么原来的键值对 key-value 将被替代成新的键值对。 * int sum(string prefix) 返回所有以该前缀 prefix 开头的键 key 的值的总和。 * * * * * 示例 1: * * * 输入: * ["MapSum", "insert", "sum", "insert", "sum"] * [[], ["apple", 3], ["ap"], ["app", 2], ["ap"]] * 输出: * [null, null, 3, null, 5] * * 解释: * MapSum mapSum = new MapSum(); * mapSum.insert("apple", 3); * mapSum.sum("ap"); // 返回 3 (apple = 3) * mapSum.insert("app", 2); * mapSum.sum("ap"); // 返回 5 (apple + app = 3 + 2 = 5) * * * * * 提示: * * * 1 <= key.length, prefix.length <= 50 * key 和 prefix 仅由小写英文字母组成 * 1 <= val <= 1000 * 最多调用 50 次 insert 和 sum * * */.
@lc code=start* * Definition for a binary tree node.
* @lc app=leetcode.cn id=648 lang=golang * * [648] 单词替换 * * https://leetcode.cn/problems/replace-words/description/ * * algorithms * Medium (59.98%) * Likes: 241 * Dislikes: 0 * Total Accepted: 57.4K * Total Submissions: 89K * Testcase Example: '["cat","bat","rat"]\n"the cattle was rattled by the battery"' * * 在英语中,我们有一个叫做 词根(root) 的概念,可以词根后面添加其他一些词组成另一个较长的单词——我们称这个词为 * 继承词(successor)。例如,词根an,跟随着单词 other(其他),可以形成新的单词 another(另一个)。 * * 现在,给定一个由许多词根组成的词典 dictionary 和一个用空格分隔单词形成的句子 * sentence。你需要将句子中的所有继承词用词根替换掉。如果继承词有许多可以形成它的词根,则用最短的词根替换它。 * * 你需要输出替换之后的句子。 * * * * 示例 1: * * * 输入:dictionary = ["cat","bat","rat"], sentence = "the cattle was rattled by * the battery" * 输出:"the cat was rat by the bat" * * * 示例 2: * * * 输入:dictionary = ["a","b","c"], sentence = "aadsfasf absbs bbab cadsfafs" * 输出:"a a b c" * * * * * 提示: * * * 1 <= dictionary.length <= 1000 * 1 <= dictionary[i].length <= 100 * dictionary[i] 仅由小写字母组成。 * 1 <= sentence.length <= 10^6 * sentence 仅由小写字母和空格组成。 * sentence 中单词的总量在范围 [1, 1000] 内。 * sentence 中每个单词的长度在范围 [1, 1000] 内。 * sentence 中单词之间由一个空格隔开。 * sentence 没有前导或尾随空格。 * * * * */.
No description provided by the author
No description provided by the author