原文链接: https://leetcode-cn.com/problems/design-linked-list 英文原文Design your implementation of the linked list. You can choose to use a singly or doubly linked list. A node in a singly linked list should have two attributes: val and next. val is the val…
标签详情
设计 分类
原文链接: https://leetcode-cn.com/problems/design-circular-queue 英文原文Design your implementation of the circular queue. The circular queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle and th…
原文链接: https://leetcode-cn.com/problems/exam-room 英文原文There is an exam room with n seats in a single row labeled from 0 to n - 1. When a student enters the room, they must sit in the seat that maximizes the distance to the closest person. If there are…
原文链接: https://leetcode-cn.com/problems/maximum-frequency-stack 英文原文Design a stack-like data structure to push elements to the stack and pop the most frequent element from the stack. Implement the FreqStack class: FreqStack() constructs an empty frequ…
原文链接: https://leetcode-cn.com/problems/rle-iterator 英文原文We can use run-length encoding (i.e., RLE) to encode a sequence of integers. In a run-length encoded array of even length encoding (0-indexed), for all even i, encoding[i] tells us the number of…
原文链接: https://leetcode-cn.com/problems/online-stock-span 英文原文Design an algorithm that collects daily price quotes for some stock and returns the span of that stock's price for the current day. The span of the stock's price today is defined as the max…
原文链接: https://leetcode-cn.com/problems/online-election 英文原文You are given two integer arrays persons and times. In an election, the ith vote was cast for persons[i] at time times[i]. For each query at a time t, find the person that was leading the ele…
原文链接: https://leetcode-cn.com/problems/complete-binary-tree-inserter 英文原文A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible. Design an algorithm to i…
原文链接: https://leetcode-cn.com/problems/number-of-recent-calls 英文原文You have a RecentCounter class which counts the number of recent requests within a certain time frame. Implement the RecentCounter class: RecentCounter() Initializes the counter with z…
原文链接: https://leetcode-cn.com/problems/time-based-key-value-store 英文原文Design a time-based key-value data structure that can store multiple values for the same key at different time stamps and retrieve the key's value at a certain timestamp. Implement…
原文链接: https://leetcode-cn.com/problems/stream-of-characters 英文原文Design an algorithm that accepts a stream of characters and checks if a suffix of these characters is a string of a given array of strings words. For example, if words = ["abc", "xyz"] a…
原文链接: https://leetcode-cn.com/problems/iterator-for-combination 英文原文Design the CombinationIterator class: CombinationIterator(string characters, int combinationLength) Initializes the object with a string characters of sorted distinct lowercase Engli…
原文链接: https://leetcode-cn.com/problems/snapshot-array 英文原文Implement a SnapshotArray that supports the following interface: SnapshotArray(int length) initializes an array-like data structure with the given length. Initially, each element equals 0. voi…
原文链接: https://leetcode-cn.com/problems/online-majority-element-in-subarray 英文原文Design a data structure that efficiently finds the majority element of a given subarray. The majority element of a subarray is an element that occurs threshold times or mo…
原文链接: https://leetcode-cn.com/problems/dinner-plate-stacks 英文原文You have an infinite number of stacks arranged in a row and numbered (left to right) from 0, each of the stacks has the same maximum capacity. Implement the DinnerPlates class: DinnerPlat…
原文链接: https://leetcode-cn.com/problems/kth-ancestor-of-a-tree-node 英文原文You are given a tree with n nodes numbered from 0 to n - 1 in the form of a parent array parent where parent[i] is the parent of ith node. The root of the tree is node 0. Find the…
原文链接: https://leetcode-cn.com/problems/design-skiplist 英文原文Design a Skiplist without using any built-in libraries. A skiplist is a data structure that takes O(log(n)) time to add, erase and search. Comparing with treap and red-black tree which has th…
原文链接: https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree 英文原文Given a binary tree with the following rules: root.val == 0 If treeNode.val == x and treeNode.left != null, then treeNode.left.val == 2 * x + 1 If treeNode.val == …
原文链接: https://leetcode-cn.com/problems/apply-discount-every-n-orders 英文原文There is a supermarket that is frequented by many customers. The products sold at the supermarket are represented as two parallel integer arrays products and prices, where the i…
原文链接: https://leetcode-cn.com/problems/tweet-counts-per-frequency 英文原文A social media company is trying to monitor activity on their site by analyzing the number of tweets that occur in select periods of time. These periods can be partitioned into sma…
原文链接: https://leetcode-cn.com/problems/product-of-the-last-k-numbers 英文原文Design an algorithm that accepts a stream of integers and retrieves the product of the last k integers of the stream. Implement the ProductOfNumbers class: ProductOfNumbers() In…
原文链接: https://leetcode-cn.com/problems/design-a-stack-with-increment-operation 英文原文Design a stack which supports the following operations. Implement the CustomStack class: CustomStack(int maxSize) Initializes the object with maxSize which is the maxi…
原文链接: https://leetcode-cn.com/problems/design-underground-system 英文原文An underground railway system is keeping track of customer travel times between different stations. They are using this data to calculate the average time it takes to travel from on…
原文链接: https://leetcode-cn.com/problems/subrectangle-queries 英文原文Implement the class SubrectangleQueries which receives a rows x cols rectangle as a matrix of integers in the constructor and supports two methods: 1. updateSubrectangle(int row1, int co…
原文链接: https://leetcode-cn.com/problems/design-browser-history 英文原文You have a browser of one tab where you start on the homepage and you can visit another url, get back in the history number of steps or move forward in the history number of steps. Imp…
原文链接: https://leetcode-cn.com/problems/design-parking-system 英文原文Design a parking system for a parking lot. The parking lot has three kinds of parking spaces: big, medium, and small, with a fixed number of slots for each size. Implement the ParkingSy…
原文链接: https://leetcode-cn.com/problems/throne-inheritance 英文原文A kingdom consists of a king, his children, his grandchildren, and so on. Every once in a while, someone in the family dies or a child is born. The kingdom has a well-defined order of inhe…
原文链接: https://leetcode-cn.com/problems/fancy-sequence 英文原文Write an API that generates fancy sequences using the append, addAll, and multAll operations. Implement the Fancy class: Fancy() Initializes the object with an empty sequence. void append(val)…
原文链接: https://leetcode-cn.com/problems/design-front-middle-back-queue 英文原文Design a queue that supports push and pop operations in the front, middle, and back. Implement the FrontMiddleBack class: FrontMiddleBack() Initializes the queue. void pushFron…
原文链接: https://leetcode-cn.com/problems/design-an-ordered-stream 英文原文There is a stream of n (idKey, value) pairs arriving in an arbitrary order, where idKey is an integer between 1 and n and value is a string. No two pairs have the same id. Design a s…