[LeetCode] fully understand the knapsack problem
0. Origin
0-1 knapsack: max min problem
Concept: there are N items in total. The weight of item I (I starts from 1) is w[i], and the value is v[i]. When the total weight does not exceed the upper limit W of the backpack, what is the maximum value that can be loaded into the backpack? Idea: define a two-dimensional array dp to store the ...
Posted by juschillin on Sat, 19 Feb 2022 01:13:37 +0100
[LeetCode - Java]350. Intersection of two arrays II (simple)
1. Title Description
2. Problem solving ideas
Intersection means to have a "global view" of the two arrays. One embodiment of the "global view" in the program is statistics. Therefore, I can use the hash table to count the occurrence times of each element in the two arrays, and then take the small value to build a ne ...
Posted by Rowno on Fri, 18 Feb 2022 13:13:51 +0100
LeetCode: Home robbery~~ Dynamic finishing
[1. House on the street, happy thief No. 1]
198. House raiding (medium)
You are a professional thief who plans to steal houses along the street. There is a certain amount of cash hidden in each room. The only restrictive factor affecting your theft is that the adjacent houses are equipped with interconnected anti-theft systems. If two adjacen ...
Posted by thipse_rahul on Thu, 17 Feb 2022 22:53:26 +0100
Implementation of rain algorithm
Implementation of one-dimensional rain algorithm
https://leetcode-cn.com/problems/trapping-rain-water/
def trap_rain_water(height):
# Idea: whether a grid can receive rainwater and how much rainwater it can receive are determined by the highest "wall" on both sides
# Traverse each grid from the second position to the pen ...
Posted by danoli3 on Thu, 17 Feb 2022 17:00:08 +0100
Dynamic programming - Fibonacci series (70. Climbing stairs, 198. Robbing homes, 213. Robbing homes II)
The original subproblem is divided into multiple subproblems, which do not need to be solved by recursive programming
Dynamic Programming (DP) requires transfer equations and boundary conditions.
catalogue
1, 70 climb stairs
1.1 Title Description
1.2 code
2, 198 raid homes and plunder houses
2.1 Title Description
2.2 code
2.2.1 there a ...
Posted by dsinicco on Thu, 17 Feb 2022 12:06:14 +0100
Leetcode notes -- modification and construction of binary tree in binary tree chapter
Catalogue of series articles
I Array type problem solving method 1: dichotomy II Array type problem solving method 2: Double finger needle method III Array type problem solving method 3: sliding window IV Array type problem solving method 4: simulation V The basic operation and classic topics of the linked list Vi Classic title of hash tab ...
Posted by crimaniak on Thu, 17 Feb 2022 05:15:27 +0100
Sequence traversal of binary tree
1. Sequence traversal
Sequence traverses a binary tree. It is to traverse the binary tree layer by layer from left to right. In order to realize sequence traversal, we need to use an auxiliary data structure, namely queue. Queue first in first out conforms to the logic of layer by layer traversal, while stack first in last out is suitab ...
Posted by matt_4013 on Wed, 16 Feb 2022 11:09:54 +0100
General code template for binary search problem
The idea of binary search is very simple, but there are many traps in the process of code writing. In particular, binary search has many variants, such as:
Find the first element equal to the target value, and return None if it does not existFind the last element equal to the target value, and return None if it does not existFind the first ele ...
Posted by marcnyc on Wed, 16 Feb 2022 08:46:17 +0100
task 01 array -- datawhale and Tianchi
task 01 array - datawhale and Tianchi
Example analysis
1. Sum of two numbers
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
int n = nums.size();
for (int i = 0 ; i < n - 1; ++ i)
for (int j = i + 1; j < n ;++ j)
{
if (nums[i] + nu ...
Posted by FD_F on Tue, 15 Feb 2022 17:29:43 +0100
The most painful programming problem in 2021
Have the old fellow heard of it? https://adventofcode.com/ This website, on the eve of Christmas every day, will start publishing programming puzzles for 25 consecutive days, attracting countless people to participate. Since I began to learn programming, I have used the topics here to exercise my programming ability.The difficulty of the topic ...
Posted by danielholmes85 on Tue, 15 Feb 2022 04:43:50 +0100