原文链接: https://leetcode-cn.com/problems/lru-cache 英文原文Design a data structure that follows the constraints of a Least Recently Used (LRU) cache. Implement the LRUCache class: LRUCache(int capacity) Initialize the LRU cache with positive size capacity.…
标签详情
设计 分类
原文链接: https://leetcode-cn.com/problems/min-stack 英文原文Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. Implement the MinStack class: MinStack() initializes the stack object. void push(int val) pushes th…
原文链接: https://leetcode-cn.com/problems/binary-search-tree-iterator 英文原文Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST): BSTIterator(TreeNode root) Initializes an object of the BSTI…
原文链接: https://leetcode-cn.com/problems/implement-trie-prefix-tree 英文原文A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this dat…
原文链接: https://leetcode-cn.com/problems/design-add-and-search-words-data-structure 英文原文Design a data structure that supports adding new words and finding if a string matches any previously added string. Implement the WordDictionary class: WordDictiona…
原文链接: https://leetcode-cn.com/problems/implement-queue-using-stacks 英文原文Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty). Implemen…
原文链接: https://leetcode-cn.com/problems/peeking-iterator 英文原文Design an iterator that supports the peek operation on an existing iterator in addition to the hasNext and the next operations. Implement the PeekingIterator class: PeekingIterator(Iterator<…
原文链接: https://leetcode-cn.com/problems/find-median-from-data-stream 英文原文The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value and the median is the mean of the two middle values. For exam…
原文链接: https://leetcode-cn.com/problems/serialize-and-deserialize-binary-tree 英文原文Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across …
原文链接: https://leetcode-cn.com/problems/range-sum-query-immutable 英文原文Given an integer array nums, handle multiple queries of the following type: Calculate the sum of the elements of nums between indices left and right inclusive where left <= right. I…
原文链接: https://leetcode-cn.com/problems/range-sum-query-2d-immutable 英文原文Given a 2D matrix matrix, handle multiple queries of the following type: Calculate the sum of the elements of matrix inside the rectangle defined by its upper left corner (row1, …
原文链接: https://leetcode-cn.com/problems/range-sum-query-mutable 英文原文Given an integer array nums, handle multiple queries of the following types: Update the value of an element in nums. Calculate the sum of the elements of nums between indices left and…
原文链接: https://leetcode-cn.com/problems/flatten-nested-list-iterator 英文原文You are given a nested list of integers nestedList. Each element is either an integer or a list whose elements may also be integers or other lists. Implement an iterator to flatt…
原文链接: https://leetcode-cn.com/problems/data-stream-as-disjoint-intervals 英文原文Given a data stream input of non-negative integers a1, a2, ..., an, summarize the numbers seen so far as a list of disjoint intervals. Implement the SummaryRanges class: Sum…
原文链接: https://leetcode-cn.com/problems/design-twitter 英文原文Design a simplified version of Twitter where users can post tweets, follow/unfollow another user, and is able to see the 10 most recent tweets in the user's news feed. Implement the Twitter cl…
原文链接: https://leetcode-cn.com/problems/insert-delete-getrandom-o1 英文原文Implement the RandomizedSet class: RandomizedSet() Initializes the RandomizedSet object. bool insert(int val) Inserts an item val into the set if not present. Returns true if the i…
原文链接: https://leetcode-cn.com/problems/insert-delete-getrandom-o1-duplicates-allowed 英文原文RandomizedCollection is a data structure that contains a collection of numbers, possibly duplicates (i.e., a multiset). It should support inserting and removing …
原文链接: https://leetcode-cn.com/problems/all-oone-data-structure 英文原文Design a data structure to store the strings' count with the ability to return the strings with minimum and maximum counts. Implement the AllOne class: AllOne() Initializes the object…
原文链接: https://leetcode-cn.com/problems/serialize-and-deserialize-bst 英文原文Serialization is converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection li…
原文链接: https://leetcode-cn.com/problems/lfu-cache 英文原文Design and implement a data structure for a Least Frequently Used (LFU) cache. Implement the LFUCache class: LFUCache(int capacity) Initializes the object with the capacity of the data structure. i…
原文链接: https://leetcode-cn.com/problems/encode-and-decode-tinyurl 英文原文Note: This is a companion problem to the System Design problem: Design TinyURL. TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/desig…
原文链接: https://leetcode-cn.com/problems/implement-magic-dictionary 英文原文Design a data structure that is initialized with a list of different words. Provided a string, you should determine if you can change exactly one character in this string to match …
原文链接: https://leetcode-cn.com/problems/map-sum-pairs 英文原文Design a map that allows you to do the following: Maps a string key to a given value. Returns the sum of the values that have a key with a prefix equal to a given string. Implement the MapSum c…
原文链接: https://leetcode-cn.com/problems/my-calendar-i 英文原文You are implementing a program to use as your calendar. We can add a new event if adding the event will not cause a double booking. A double booking happens when two events have some non-empty …
原文链接: https://leetcode-cn.com/problems/my-calendar-ii 英文原文You are implementing a program to use as your calendar. We can add a new event if adding the event will not cause a triple booking. A triple booking happens when three events have some non-emp…
原文链接: https://leetcode-cn.com/problems/my-calendar-iii 英文原文A k-booking happens when k events have some non-empty intersection (i.e., there is some time that is common to all k events.) You are given some events [start, end), after each given event, r…
原文链接: https://leetcode-cn.com/problems/prefix-and-suffix-search 英文原文Design a special dictionary with some words that searchs the words in it by a prefix and a suffix. Implement the WordFilter class: WordFilter(string[] words) Initializes the object w…
原文链接: https://leetcode-cn.com/problems/kth-largest-element-in-a-stream 英文原文Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element. Implement KthLargest cla…
原文链接: https://leetcode-cn.com/problems/design-hashset 英文原文Design a HashSet without using any built-in hash table libraries. Implement MyHashSet class: void add(key) Inserts the value key into the HashSet. bool contains(key) Returns whether the value …
原文链接: https://leetcode-cn.com/problems/design-hashmap 英文原文Design a HashMap without using any built-in hash table libraries. Implement the MyHashMap class: MyHashMap() initializes the object with an empty map. void put(int key, int value) inserts a (k…
1 / 4