Quick sorting embodies the idea of divide and conquer. Determine the final position of a number each time, place it in the correct position, and then quickly sort the arrays at both ends in the same way through recursion.
It should be noted that when using quick sort, the decision number needs to be taken randomly, which is called ...
Posted by ferronrsmith on Thu, 10 Mar 2022 17:33:18 +0100
Please implement a myAtoi(string s) function to convert the string into a 32-bit signed integer (similar to the atoi function in C/C + +).
The algorithm of the function myAtoi(string s) is as follows:
Read in the string and discard useless leading spacesCheck whether the next character (assuming it is not at the end of the character) ...
Posted by agnaldovb on Wed, 09 Mar 2022 10:09:35 +0100
Preorder traversal of binary tree
Give you the root node of the binary tree, root, and return the preorder traversal of its node value.
Input: root = [1,null,2,3]
Input: root = 
Input: root = 
Method 1: recursion
For tree traversal, recursive method ...
Posted by Kaizard on Wed, 09 Mar 2022 08:42:32 +0100
Plates between candles
Here is a long table with plates and candles lined up on it. Give you a string s with subscript starting from 0. It only contains the characters' * 'and' | ', where' * 'represents a plate and' | 'represents a candle.
At the same time, give you a two-dimensional integer array queries with subscript starting from 0, where ...
Posted by lucerias on Tue, 08 Mar 2022 15:42:36 +0100
2055. Plates between candles [medium] [daily]
Record the number of plates in front of each position with cnt; Use left to record the position of the first candle on the left of the current position; Use right to record the position of the first candle on the right of the current position.Traverse each query, and define x as the posit ...
Posted by Schlo_50 on Tue, 08 Mar 2022 10:11:25 +0100
2055. Plates between candles
Method 1: dichotomy + prefix and
Data preprocessing: scan the string s from front to back, record the candle subscript in the array list (the array is strictly incremented - binary basis), and preprocess the prefix and array of the plateTraverse queries:
For any query
Posted by chokies12 on Tue, 08 Mar 2022 09:29:59 +0100
A matrix diagonal is a diagonal line starting from an element in the topmost row or leftmost column of the matrix, along the lower right direction to the end of the matrix. For example, the matrix mat has 6 rows and 3 columns. The diagonal of the matrix ...
Posted by ferdi on Tue, 08 Mar 2022 09:11:44 +0100
Given an integer array prices, where the i-th element represents the stock price on the i-th day; The nonnegative integer fee represents the handling fee for trading stocks. You can complete transactions indefinitely, but you need to pay a handling fee for each transaction. If you have bought a stock, you can't continue to b ...
Posted by ruddyu78 on Tue, 08 Mar 2022 00:22:25 +0100
Regular Expression Matching Give you a string s and a character rule p, please implement a support '.' Matches the regular expression of '*'.
‘.’ Match any single character '*' matches zero or more preceding elements The so-called matching is to cover the whole string s, not part of the string.
Input: s = &q ...
Posted by Robert Plank on Mon, 07 Mar 2022 19:20:41 +0100
String correlation functions and methods
Correlation functions: len, str, eval
1. Str (data) - convert the specified data into a string (when converting, put quotation marks directly outside the printed value of the data)
list1 = [10,20,30]
str(list1) #'[10, 20, 30]'
2. Eval (string) - evaluates th ...
Posted by richza on Mon, 07 Mar 2022 02:40:24 +0100