5676. Minimum operands for generating alternating binary strings (question 1)
subject
Give you a string s consisting only of the characters' 0 'and' 1 '. In one step, you can change any '0' to '1', or '1' to '0'.
Alternating string is defined as: if two adjacent characters are not equal in the string, the string is an alternating string. ...
Posted by farsighted on Tue, 19 Apr 2022 01:43:33 +0300
Implement the StreamChecker class as follows:
StreamChecker(words): Constructor, init the data structure with the given words.
query(letter): returns true if and only if for some k >= 1, the last k characters queried (in order from oldest to newest, including this letter just queried) spell one of the words in the given list.
Example:
Str ...
Posted by Chinese on Mon, 18 Apr 2022 19:56:52 +0300
subject
Portal
In MATLAB, there is a very useful function reshape, which can reshape a matrix into another new matrix of different sizes, but retain its original data. A matrix represented by a two-dimensional array and two positive integers r and c are given to represent the number of rows and columns of the matrix to be reconstructed res ...
Posted by dipenmistry on Mon, 18 Apr 2022 15:25:30 +0300
General points:
Clarify the meaning of dp. During initialization, pay attention to limiting the input. After initialization, pay attention to the iteration after initialization! Start after initialization! Start after initialization!
Step: define the meaning and recurrence formula, and create dp; Initialize dp; Iteration dp
Difference between ...
Posted by Drewser33 on Mon, 18 Apr 2022 07:39:28 +0300
Given a 2-dimensional grid of integers, each value in the grid represents the color of the grid square at that location.
Two squares belong to the same connected component if and only if they have the same color and are next to each other in any of the 4 directions.
The border of a connected component is all the squares in the connected compon ...
Posted by peterg012 on Mon, 18 Apr 2022 02:18:38 +0300
1, Problem description
Find the value of the expression according to the inverse Polish representation. Valid operators include +, -, *, /. Each operand can be an integer or another inverse Polish expression.
Note: integer division only retains the integer part; The given inverse Polish expression is always valid. In other words, an expressio ...
Posted by gatoruss on Sun, 17 Apr 2022 17:47:56 +0300
Sliding window median
The median is the number in the middle of the ordered sequence. If the length of the sequence is even, there is no middle number; At this time, the median is the average of the two numbers in the middle. For example:
[2,3,4], the median is 3[2,3], the median is (2 + 3) / 2 = 2.5
Give you an array nums, with a window of ...
Posted by ready2drum on Sun, 17 Apr 2022 12:46:56 +0300
Title: longest common prefix
Write a function to find the longest common prefix in the string array.
If there is no public prefix, the empty string '' is returned.
Example:
Input: strs = ["flower","flow","flight"]
Output:"fl"
Input: strs = ["dog","racecar","car"]
Output:""
Explanation: the input does not have a public prefix.
Topic inter ...
Posted by jfs0479 on Sun, 17 Apr 2022 09:21:35 +0300
Dichotomy algorithm
The binary algorithm is divided into integer binary and floating-point binary. Floating-point binary is easier
I Original question link
Given an array of integers of length n in ascending order and q queries.
For each query, the start and end positions of an element k are returned (the positions are counted from 0).
I ...
Posted by jerbecca on Sat, 16 Apr 2022 17:56:37 +0300
2022.4.15
Swordfinger Offer 06. Print chain list from end to end
Simple difficulty
Enter the head node of a list of chains and return the value of each node (in an array) from the end to the end.
Ideas:
Create an array, traverse the array upside down, and follow the list of chains to reverse the effect. (wastes space) With arraylist, ...
Posted by Bit343 on Fri, 15 Apr 2022 20:00:53 +0300