Sword finger offer Second Edition

Sword finger offer Second Edition 1. Duplicate numbers in the array (Offer-03) Use both sets and dictionaries. var findRepeatNumber = function(nums) { let map = new Set() for(let i = 0; i < nums.length; i++) { const n = nums[i] if(map.has(n)) { return n } map.add(n) } }; 2. Search ...

Added by ravegti on Thu, 10 Mar 2022 11:03:54 +0200

Still using recursion, try iteration

Recursion & iteration recursion Recursion is often used to describe the process of repeating things by self similar method. In mathematics and computer science, it refers to the method of using function itself in function definition. (A calls A) iteration Repeat the activity of the feedback process, and the result of each iteration will ...

Added by scrypted on Tue, 08 Mar 2022 11:56:51 +0200

Monotone queue optimization for multiple knapsack problems

Monotone queue optimization for multiple knapsack problems Warm tips: it's better to eat dessert first and then enter the dinner~ 0-1 backpack problem (dessert) https://www.acwing.com/problem/content/2/ Simple solution #include <iostream> using namespace std; const int N = 1010; int n, m; //n number of items m maximum capacit ...

Added by hardyvoje on Mon, 07 Mar 2022 12:37:59 +0200

2022-02-13 daily clock in: problem fine brush

2022-02-13 daily clock in: problem fine brush Write in front "After being proficient, these things may be as plain as drinking water, but they can bring great happiness to beginners. I always feel that whether we can always maintain the enthusiasm and concentration like beginners determines how far we can go and how good we can do someth ...

Added by mabwi on Sun, 06 Mar 2022 14:49:35 +0200

[title record] - ICPC Dalian 2016

Title set address ICPC Dalian 2016 A - wresting match Title address A - Wrestling Match There are n athletes and m games. It is known that x are good athletes and y are bad athletes. Each game is a good athlete and a bad athlete. Ask whether all athletes can be divided into good athletes or bad athletes according to the known information. ...

Added by conquest on Sun, 06 Mar 2022 04:18:26 +0200

Maximum subarray sum (greedy algorithm and dynamic programming method)

Note that you are looking for a continuous array!! 1, Dynamic programming method class Solution { public int maxSubArray(int[] nums) { //Create an array dp as large as nums int[] dp=new int[nums.length]; //dp[i] represents the sum of the largest subarray of the array ending in num [i] dp[0]=nums[0]; ...

Added by unclemid on Sat, 05 Mar 2022 17:31:24 +0200

leetcode363 - the maximum value of the rectangular area does not exceed the sum of K (prefix and + dichotomy) (TreeSet or auxiliary array dynamic return)

introduce My LeetCode homepage, one problem one solution Tags: queue, dynamic programming, binary search 363. The rectangular area does not exceed the maximum value of K and Difficulty difficulty 363. The rectangular area does not exceed the maximum value of K and: https://leetcode-cn.com/problems/max-sum-of-rectangle-no-larger-than-k ...

Added by Piba on Wed, 02 Mar 2022 01:12:42 +0200

Donghua advanced level oj31-40

#include<stdio.h> #include<string.h> #include<algorithm> int e[110][110],culture[110][110],country[110],visit[110];//Adjacency matrix of countries and cultures int N,K,M,S,T,learn[110],ans; int judge(int x,int y)//Judge whether there is any conflict between the learned culture and x countries { if(culture[ country[y] ...

Added by GKWelding on Tue, 01 Mar 2022 12:31:36 +0200

[daily question 1] preparing for the Blue Bridge Cup -- Python programming | Day06 | decorative beads | real question code analysis

๐Ÿ’– About the author: Hello, I'm brother cheshen, cheshen at No. 18 Fuxue road ๐Ÿฅ‡ โšก About - > Che Shen: the fastest time from the bedroom to the laboratory is 3 minutes, and the slowest time is 3.5 minutes (that half minute is actually waiting for the traffic light) ๐Ÿ“ Personal homepage: Drivers only need cars and hands, and the pressure com ...

Added by MetaDark on Tue, 01 Mar 2022 01:35:58 +0200

[explanation of 2021 Blue Bridge Cup Java-B provincial Tournament (Game 2)]

1, Surplus (water) stay C / C + + / J a v ...

Added by kjeldoran on Mon, 28 Feb 2022 13:15:00 +0200