Traversal of binary tree (recursion + iteration)
Summarize the four traversal methods of binary tree, using recursion and iteration. The recursive code is relatively simple, and the iterative code is relatively complex.
1, Preorder traversal
(here, take the printed results as an example, you can also use ArrayList to store the val in the subtree)
thinking
Recursion: first the root node ...
Posted by Naug on Sat, 02 Oct 2021 15:00:13 -0700
This blog is about stack in LeetCode I wrote
Question 1 (corresponding to question 20 of LeetCode question bank) (simple question!)
(of course, if you don't understand your own summary, you can go to the website and read the corresponding topic to see the solution!)
Title: valid parentheses (parenthesis matching problem of string)
(I wrote a hundred lines at the first time, but I could ...
Posted by jeroom on Sat, 02 Oct 2021 13:12:27 -0700
Sword finger offer (Second Edition) - the lowest common ancestor of two nodes in the tree
PS: Sword finger offer is not only an interview guide that many students will refer to when looking for a job, but also an algorithm Guide (the main reason why it is so popular is that it provides a step-by-step optimization solution, which I think is very friendly). Now many Internet algorithm interview questions can be found here. For the con ...
Posted by ccb on Fri, 01 Oct 2021 18:26:44 -0700
CSP 2021-09-2 non zero segment division problem solution
Title Link
The original question is linked in Non zero segment division , I won't post the title. Given an array, you can divide the array into as many continuous non-zero segments as possible by changing the number below the threshold into 0.
Topic analysis
A very direct idea is: there are m different non-zero values in the array with l ...
Posted by AaZmaN on Fri, 01 Oct 2021 17:05:23 -0700
06_JavaScript data structure and algorithm one-way linked list
JavaScript data structure and algorithm (VI) one way linked list
Cognitive linked list
Linked lists and arrays
Like arrays, linked lists can be used to store a series of elements, but the implementation mechanism of linked lists and arrays is completely different.
array
Storing multiple elements, arrays (or lists) are probably the most co ...
Posted by _will on Fri, 01 Oct 2021 14:48:26 -0700
Acwing - 131. The largest rectangle in the histogram
131. The largest rectangle in the histogram - AcWing question bank
Title Description
tag: monotone stack
A histogram is a polygon consisting of a series of rectangles aligned at a common baseline.
Rectangles have equal widths, but can have different heights.
For example, the left side of the legend shows a histogram composed of rect ...
Posted by coelex on Fri, 01 Oct 2021 12:02:00 -0700
LRU implementation principle
preface
We often use cache to improve data query speed. Due to the limited cache capacity, when the cache capacity reaches the upper limit, we need to delete some data to make room so that new data can be added. Cache data cannot be deleted randomly. Generally, we need to delete cache data according to some algorithm. Common elimination algori ...
Posted by n14charlie on Fri, 01 Oct 2021 11:22:00 -0700
pclpy statistical filtering
1, Algorithm principle
1. Principle overview
the point cloud data set generated by lidar sometimes receives echo signals incorrectly, which will lead to some wrong values. Due to the influence of measurement errors caused by scanning results, errors will inevitably occur in other processing of the point cloud, and some noise ...
Posted by nimzie on Thu, 30 Sep 2021 17:47:53 -0700
LeetCode 15 sum of three numbers
LeetCode 15 sum of three numbers
Title Description
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. OJ link
Train of thought analysis
First, special cases shall be handled
If the array is empty, an empty c ...
Posted by zander213 on Thu, 30 Sep 2021 12:18:43 -0700
Double pointer topic summary
(Kago double pointer chapter punch in)
1. Remove element
thinking
It can be solved directly. But the time complexity will be very large. A simpler way is to speed the pointer. The idea of this fast and slow pointer is that the slow pointer points to the position of the inserted character (treat the array as a new array), and the fast poi ...
Posted by markuatcm on Thu, 30 Sep 2021 11:55:40 -0700