Algorithm_ Binary tree_ Nearest common ancestor of binary tree
Nearest common ancestor of binary tree
leetcode link
1. Two solutions
Recursion - postorder traversal
Idea: this problem wants to find the nearest common ancestor of two nodes, so we have to traverse the tree from bottom to top, judge the two children first, and then judge the logic of the root node, so we think of using post order trav ...
Added by ryanfern86goa on Wed, 22 Dec 2021 03:03:32 +0200
LeetCode|Python|400 question classification and question brushing record - recursion
Recursive / DFS/BFS
In constant update
51. Queen n
The n ∧ queen problem studies how to place n ∧ queens in n × N's chessboard, and the Queens can't attack each other.
Give you an integer n, which returns the solution of all different , queen problems.
Each solution contains a different chess placement scheme for the n ...
Added by zuessh on Wed, 22 Dec 2021 02:58:37 +0200
LeetCode best time to buy and sell stocks series summary
LeetCode best time to buy and sell stocks series summary
This kind of dynamic programming is optimized from two-dimensional dynamic gauge to one-dimensional dynamic gauge. Greed can also be used in some problems.
catalog:
121 the best time to buy and sell stocks 1 122 the best time to buy and sell stocks 2 123the best time to buy and sell st ...
Added by interactive on Tue, 21 Dec 2021 18:41:28 +0200
LeetCode brush notes binary search local order
Local ordering of binary search
We already know that binary search is a search algorithm for finding a specific element in an ordered array.
What if an array is not globally ordered, but locally ordered? At this time, we can use the divide and conquer strategy. We can perform binary search in the locally ordered interval, and then combine eac ...
Added by Rayman3.tk on Tue, 21 Dec 2021 07:36:47 +0200
Algorithm learning Leetcode -- sum of three numbers
preface
Give you an array num containing n integers. Judge whether there are three elements a, b and c in num, so that a + b + c = 0? Please find all triples with sum 0 and no repetition.
Note: the answer cannot contain repeated ternary
1, Violent solution
Seeing that the problem is summed according to conditions, the first thing ...
Added by Buchead on Mon, 20 Dec 2021 15:12:14 +0200
iOS LeetCode ☞ rebuild queue based on height
Suppose a group of people with disordered order stand in a queue, and the array people represents the attributes of some people in the queue (not necessarily in order). Each people[i] = [hi, ki] indicates that the height of the ith person is hi, and there is ki people whose height is greater than or equal to hi in front.
Please reconstruct and ...
Added by Darghon on Mon, 20 Dec 2021 13:35:32 +0200
[learning 100 million points every day] - OJ questions of stack and queue
1. Implement stack with queue
graphic
Since two queues are used to implement the stack, it must be related to the nature of the queue. It must be changed back and forth. Let's take a look at this process.
code implementation
typedef struct {
Queue* q1;
Queue* q2;
} MyStack;
/** Initialize your data structure here. */
M ...
Added by jstarkey on Mon, 20 Dec 2021 06:19:59 +0200
Force buckle 68 Align text left and right
subject
Given an array of words and a length maxWidth, rearrange the words into text with exactly maxWidth characters per line and aligned left and right ends. You should use "greedy algorithm" to place a given word; That is, put as many words in each line as possible. If necessary, it can be filled with space '' so that each line ha ...
Added by melsi on Mon, 20 Dec 2021 05:24:05 +0200
The inner winding road of thirteen
Algorithm learning Chapter 1
Palindrome number
Difficulty: simple
Title: Give you an integer X. if x is a palindrome integer, return true; Otherwise, false is returned. Palindromes are integers whose positive (left to right) and reverse (right to left) reads are the same. For example, 121 is a palindrome, not 123.
Idea: First convert an int ...
Added by Youko on Sun, 19 Dec 2021 22:12:21 +0200
Link list inversion of LeetCode daily question
preface:
Hello, everyone. Today is the eighth day of LeetCode's daily question. What I share is the reversal of the linked list and the difficulty coefficient of two stars! No more nonsense, let's start with the topic!
1.1 subject requirements
Topic type: linked list inversion
Title Content: reverse the link order of the single linked ...
Added by papapax on Sun, 19 Dec 2021 12:29:32 +0200