Preorder traversal of leetcode 144 binary tree

Preorder traversal of binary tree Title Description Give you the root node of the binary tree, root, and return the preorder traversal of its node value. Example 1: Input: root = [1,null,2,3] Output:[1,2,3] Example 2: Input: root = [] Output:[] Example 3: Input: root = [1] Output:[1] Method 1: recursion For tree traversal, recursive method ...

Posted by Kaizard on Wed, 09 Mar 2022 08:42:32 +0100

Ordinary segment tree

Ordinary segment treeProblem introductionGiven that a sequence has n (n < = 100000) elements, there are the following two basic operationsQuery: find the sum of all elements in a given interval [l..r]Modify: modify the value of an element.Task: output the value of each query.Task quantity m (m < = 100000), only the above two operations.Na ...

Posted by Arryn on Mon, 07 Mar 2022 08:32:08 +0100

[algorithm] recursion, search and sorting

1. Recursion Find duplicate Find a way to divideFind recursive formula or equivalent transformation Find change The variable is usually used as a parameter Find boundary Simple basic questions (practice three steps) Find the factorial of n public class demo01 { public static void main(String[] args) { int a = f1(4); System.o ...

Posted by gareh on Tue, 22 Feb 2022 17:43:36 +0100

Full Permutation & permutation and combination to eliminate the difference of duplicate data

Full Permutation & permutation combination Realize the nuance of excluding duplicates This article expounds the full arrangement method and arrangement combination. The permutation and combination here uses an example to expand * * (different combinations of target values)** The first is full permutation, which is realized in two ways: 1 ...

Posted by newbtophp on Sun, 20 Feb 2022 12:24:07 +0100

Three solutions to change in Python

Change The most direct solution to the change problem is the greedy strategy. For example: for coins with face values of 1, 5, 10 and 25, solve the minimum number of coins required to exchange 63 yuan. The idea of greedy strategy is to constantly use the coins with the largest face value to try. No, in this case, 25 coins are used to try the ...

Posted by dbrimlow on Sat, 12 Feb 2022 08:55:23 +0100

java - poi recursively export tree structure Excel, import tree structure Excel, tree structure recursive query, add, modify and delete.

1, Table structure design, import and export templates. Note: the structure of blogger tree is 8-level structure, which is divided into two tables due to business relationship. This table is divided into four levels, and the structure is as follows: Building unit floor room Excel The table item name field is obtained from the first table ...

Posted by harmor on Wed, 09 Feb 2022 10:35:49 +0100

File class, recursive algorithm, IO stream

1, File class Class represents platform independent files and directories File # can create, delete and rename files and directories, but file cannot access the file content itself. If you need to access the file content itself, you need to use input / output streams. 1. Constructor: public class TestFile { public static void main(Strin ...

Posted by fredmeyer on Wed, 09 Feb 2022 03:46:11 +0100

Interviewer: you don't even know how to restore the binary tree?

Recover the binary tree according to traversal In the knowledge of binary tree, finding or traversing binary tree is a very important knowledge point. Because the author only paid attention to the traversal process of binary tree before, but ignored the importance of the inverse process of recovering binary tree from traversal. When I saw an a ...

Posted by jarriola on Tue, 08 Feb 2022 10:29:10 +0100

Algorithm self-study notes: binary search tree search operation

In this paper, we continue to build a binary tree, and the rest of the methods API: size() returns the total number of nodes select(int k) returns the key ranked K in the tree, that is, K keys are less than it Rank (key) returns the ranking of a given key, that is, the number less than the key in the tree To implement these methods, we ...

Posted by magie on Fri, 04 Feb 2022 08:56:12 +0100

Linked list problem, how to deliver the turtle gracefully?

preface Hello, I'm "programmer bear" from Huawei. Most children's shoes know that when solving problems related to "linked list", the commonly used problem-solving routines mainly include "double pointer", "iteration" and "virtual head node". Today, "Little Bear" introduces the strat ...

Posted by manchuwok on Tue, 01 Feb 2022 13:24:15 +0100