100. Same tree (2021-05-13)
100. Same tree
Link: https://leetcode-cn.com/problems/same-tree/
See the link for the title description.
Solution 1: breadth first search
What took advantage of was the problem of traversing the binary tree just yesterday, so it was completed smoothly today. At the beginning, I wanted to complete the search with depth first, but the re ...
Posted by insub2 on Fri, 11 Feb 2022 15:10:39 +0100
Stack and queue force deduction problem opening brush
Question 1: Force deduction 232 questions
Problem solving ideas:
This is related to the characteristics of stacks and queues. As we all know, stacks meet the requirements of "first in and last out", while queues meet the requirements of "first in and first out", so smart humans think of using two stacks to realize queues. ...
Posted by glenelkins on Fri, 11 Feb 2022 10:14:14 +0100
Double pointer algorithm - sum of two numbers II
Give you an integer array numbers with subscript starting from 1. The array has been arranged in non decreasing order. Please find two numbers in the array that meet the sum of addition and equal to the target number target. If the two numbers are numbers[index1] and numbers[index2] respectively, then 1 < = index1 < index2 < = numbers ...
Posted by Hobgoblin11 on Fri, 11 Feb 2022 10:01:40 +0100
Leetcode 2021 annual brush questions by type summary backtracking method (python)
Example 1: 77 combination
77. Portfolio This question is mainly to understand the basic use of backtracking algorithm. Take the given n=4,k=2 as an example (source: Code Capriccio)
As can be seen from the above figure, the logic of the code is to insert for loop traversal in recursion. The exit condition of a recursive loop is when the path ...
Posted by zeno on Fri, 11 Feb 2022 07:13:06 +0100
Square root of x (simple)
LeetCode 69. Square root of X title link:
Title Description:
Implement the int sqrt(int x) function. Calculates and returns the square root of X, where x is a nonnegative integer. Since the return type is an integer, only the integer part of the result will be retained, and the decimal part will be rounded off.
Example 1:
Input: 4 Output ...
Posted by lady1dc on Thu, 10 Feb 2022 20:28:54 +0100
LeetCode problem solution (500-1000, continuously updated, part2)
part1(1-500), part3(1000-*)
502. IPO
Given k,w,profits Array and capital Array. k Indicates the maximum number of tasks that can be completed. w Is the initial capital. profits Is the benefit of each task. capital This is the initial funding required to start this task. After completing one task at a time, add the income to the capital. Ask ...
Posted by EPJS on Thu, 10 Feb 2022 16:45:05 +0100
String matching Pabinkarp
Title:
Judge whether the string s contains the string p.
The input takes up two lines: String s and string p.
The output contains the starting subscript of string p in string s. if there are multiple matches, all of them will be output, and each output will occupy one line.
Case:
Input:
ABABABA
ABA
Output:
0
2
4
Preliminarily explore t ...
Posted by defect on Thu, 10 Feb 2022 06:11:37 +0100
LeetCode#36. Effective Sudoku
Title:
Please judge whether a Sudoku of {9 x 9 is effective. You only need to verify whether the numbers you have filled in are valid according to the following rules.
The numbers , 1-9 , can only appear once in each line. The numbers ^ 1-9 ^ can only appear once in each column. The numbers ^ 1-9 ^ can only appear once in each ^ 3x3 ^ ...
Posted by crowezr on Thu, 10 Feb 2022 04:47:54 +0100
[force buckle] the binary tree is transformed into the next node of the linked list binary tree. The binary tree and the path with a certain value print the binary tree into multiple lines
Brush on the buckle these days
Some binary tree problems, rely on the basis (pre order traversal ~ middle order traversal ~ subsequent traversal ~ sequence traversal) to solve the problem. Of course, there are many methods to solve the problem.
[introduce the basic traversal first]
Preorder traversal
The first step is to ...
Posted by neller on Thu, 10 Feb 2022 03:26:03 +0100
Leetcode question brushing record: 1 sum of two numbers (array hash)
Leetcode question brushing record: 1 sum of two numbers (array hash)
Title stem:
Given an integer array nums and an integer target value target, please find the two integers with and as the target value target in the array and return their array subscripts. You can assume that each input will correspond to only one answer. However, the sam ...
Posted by Bullit on Wed, 09 Feb 2022 06:03:33 +0100