232. Implement a queue with a stack
Please use only two stacks to implement a first-in-first-out queue. The queue should support all operations supported by general queues (push, pop, peek, empty):
Implement the MyQueue class:
void push(int x) pushes element x to the end of the queueint pop() removes and returns an element from t ...
Posted by planethax on Wed, 16 Nov 2022 02:28:04 +0300
Day13. Sliding window maximum value, top K high frequency elements
0239. Sliding window maximum
Link: 0239. Sliding window maximum
Monotonic queue: The queue is monotonic. In order to maintain this monotonicity, when adding elements to the tail of the queue, if the previous element and the current element do not satisfy the monotonic relatio ...
Posted by papacostas on Thu, 10 Nov 2022 19:11:56 +0300
gives you an array of distinct integers, where locations[i] represents the location of the ith city. At the same time, it gives you start, finish and fuel, which respectively represent the departure city, destination city and the total amount of gasoline you have initially.
In each step, if you are in city i , you can choose any city j such th ...
Posted by neonorange79 on Thu, 10 Nov 2022 01:19:00 +0300
First, the basic concept of operator overloading
Operator overloading is to redefine an existing operator and give it another function to adapt to different data types (operator overloading cannot change the original meaning. It cannot change the meaning of the underlying type)
Operator overloading is just a syntactic convenience, i ...
Posted by rdhatt on Fri, 07 Oct 2022 11:27:09 +0300
>_< Now we need to arrange a timetable for the students (the learning order of the course)
But it's not that simple:
Course 0, course 4
Might as well draw a Graph and try i ...
Posted by noimad1 on Wed, 25 May 2022 22:41:14 +0300
138. Copy linked list with random pointer
Given a linked list, each node contains an additional random pointer that can point to any node in the linked list or to an empty node.
Ask to return a deep copy of this linked list.
A deep copy means that the source object and the copied object are independent of each other, and changes to either objec ...
Posted by Iokina on Wed, 25 May 2022 21:50:30 +0300
Given a string containing only numbers, restore it and return all possible IP address formats.
A valid IP address consists of exactly four integers (each integer is between 0 and 255), with '.' between integers separate.
Output: [255.255.11.135 "," 255.255.111.35 "]
Enter the number N and print out the decimal number from 1 to the maximum n digits in sequence. For example, if you enter 3, 1, 2 and 3 will be printed up to the maximum 3 digits 999.
input: n = 1
Instead of printing, return a list of integers
n is a positive integer
Posted by starvator on Tue, 24 May 2022 18:20:56 +0300
The first question of LeetCode brushing questions, the use of the sum of two numbers and the hash table
Given an integer array nums and a target value target, please find the two integers in the array whose sum is the target value, and return their array indices.
You can assume that there will only be one answer for each input ...
Posted by 8ta8ta on Tue, 24 May 2022 17:54:50 +0300
1, Topic analysis
(1) The problem can be abstracted as detecting whether a directed graph has a ring. If yes, return False; If not, return True.
(2) For a directed graph, we can delete nodes with zero penetration one by one. For each deleted node, the connected directed line segment will also be deleted (i.e. the penetration of this point as ...
Posted by judgy on Tue, 24 May 2022 11:48:30 +0300