二叉树的遍历
二叉树 二叉树是每个结点最多有两个子树的树结构。通常子树被称作“左子树”(left subtree)和“右子树”(right subtree)。 二叉树的定义和结构 struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {} }; 以存储 int 值为数据的二叉树为例,每一个二叉树节点有一个左节点和右节点,故以此建立树节点的结构体,初识孩子指针为 ...
线段树
线段树的作用 线段树是一种二叉搜索树,它能以较低时间复杂度 O(logN) 得解决大规模求和、gcd 等 空间复杂度为 2N,但实际应用时还需 4N 的空间 查询和单点更改的代码实现 class NumArray { public: int *tree; int size; NumArray(vector<int> nums) { size = nums.size(); //size 储存原始数据的数量 tree = new int[size * 4]; ...
First-blog
First Blog Formats Testing Testing testing Hyperlink 行内形式:Github 自动链接:Github http://github.com/GZTimeHacker List first item second item third item Table 表头 1 表头 2 表头 3 表头 4 默认左对齐 左对齐 居中对其 右对齐 默认左对齐 左对齐 居中对其 右对齐 默认左对齐 左对齐 居中对其 右对齐 Code #include<iostream> using namespace std; in...