[algorithm] the course schedule is not simple -- topological sorting

  introduction   >_< Now we need to arrange a timetable for the students (the learning order of the course) But it's not that simple:   curriculum Precursor course Course 0 Course 1 Course 0, course 4 Course 2 Course 3 Course 0 Course 4 Course 5 Course 3 Course 6 Course 3   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

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

Restore IP address

Title Description 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. Examples Input: "25525511135" Output: [255.255.11.135 "," 255.255.111.35 "] Recu ...

Posted by erax on Tue, 24 May 2022 21:17:18 +0300

[daily question] question 24: print from 1 to the maximum n digits

Title Description 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. Example 1: input: n = 1 output: [1,2,3,4,5,6,7,8,9] explain: Instead of printing, return a list of integers n is a positive integer Proble ...

Posted by starvator on Tue, 24 May 2022 18:20:56 +0300

#LeetCode brush questions#, #The sum of two numbers#, #Hash table#

The first question of LeetCode brushing questions, the use of the sum of two numbers and the hash table Topic description 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

[force deduction and question brushing] (207. Course schedule) record

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

LeetCode 130. Surrounded area | Python

130. Surrounding areas Title Source: LeetCode https://leetcode-cn.com/problems/surrounded-regions subject Given a two-dimensional matrix containing 'X' and 'o' (letter O). Find all areas surrounded by 'X' and fill all 'O' in these areas with 'X'. Example: X X X X X O O X X X O X X O X X After running your function, the matrix becomes: X X X X X ...

Posted by sps on Tue, 24 May 2022 10:58:14 +0300

Knapsack problem of dynamic programming

In dynamic programming, the right class of problems is derived from the knapsack problem. Its core is to give an array nums[i] and select some data from nums[i] according to some requirements to meet some requirements More subdivision is whether the elements in a pile of sets can be taken repeatedly. Then someone on the Internet raised the q ...

Posted by corrupshun on Tue, 24 May 2022 08:27:05 +0300

[beginners climb Leetcode79] Word Search

Leetcode79 medium\color{#FF4500}{medium}medium Click to enter the original question link: Word Search Related topics: word search II word search II [tag] backtracking search, C++ ASCII subject Discription Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell ...

Posted by snaack on Tue, 24 May 2022 01:57:25 +0300

Data structure and algorithm - backtracking algorithm 1

Backtracking algorithm framework Backtracking is closely related to DFS. Backtracking means "withdraw one step" Solving a backtracking problem is actually a traversal process of decision tree. Just think about three questions: Path: choices already made; Selection list: currently available selections; End condition: a condition tha ...

Posted by BizLab on Mon, 23 May 2022 11:25:19 +0300