本文中案例都会在上传到git上,请放心浏览 git地址:https://github.com/muxiaonong/Spring-Cloud/tree/master/order-lock 本文会使用到 三台 redis 独立服务器,可以自行提前搭建好 前言 在Java中,我们对于锁会比较熟悉,常用的 ...
分类:
其他好文 时间:
2020-07-18 15:49:42
阅读次数:
60
链接:https://leetcode-cn.com/problems/unique-binary-search-trees-ii/ 代码 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNo ...
分类:
其他好文 时间:
2020-07-18 13:39:30
阅读次数:
56
链接:https://leetcode-cn.com/problems/binary-tree-inorder-traversal/ 代码 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNo ...
分类:
其他好文 时间:
2020-07-18 11:34:31
阅读次数:
66
A - Distance in Tree CodeForces - 161D 题目大意:树是一个不包含任何圈的连通图。树的两个节点之间的距离是节点之间最短路径的长度(也就是边的长度)。 给定一棵有n个节点的树和一个正整数k,找出距离恰好为k的不同节点对的数量。注意,节点对(v, u)和节点对(u, ...
分类:
其他好文 时间:
2020-07-18 11:28:18
阅读次数:
57
此题和之前的剑指offer32-I、II.从上到下打印二叉树大致相同在BFS的基础上只是添加了一个重排序的过程。具体代码如下: 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * st ...
分类:
其他好文 时间:
2020-07-18 11:18:07
阅读次数:
58
题目链接 题目大意:给出一颗含有$n$个结点的树,每个节点有一个颜色。求树中每个子树最多的颜色的编号和。 树上启发式合并(dsu on tree)。 我们先考虑暴力怎么做。遍历整颗树,暴力枚举子树然后用桶维护颜色个数。这样做是$O(n^2)$的,显然会T。我们需要一种更快的算法:树上启发式合并。 关 ...
分类:
其他好文 时间:
2020-07-17 22:21:39
阅读次数:
58
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), r ...
分类:
其他好文 时间:
2020-07-17 13:55:38
阅读次数:
71
强烈推荐视频: 堆排序(heapsort) 代码: #include <iostream> #include <stdlib.h> using namespace std; void heapify(int tree[], int n, int i) { if (i >= n) return; in ...
分类:
编程语言 时间:
2020-07-17 01:23:04
阅读次数:
99
题目链接:https://leetcode-cn.com/problems/n-ary-tree-postorder-traversal/ 方法一递归法:先访问子节点,然后访问根。LeetCode代码: /* // Definition for a Node. class Node { public ...
分类:
其他好文 时间:
2020-07-16 21:39:10
阅读次数:
79
Minimum Size Subarray Sum Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which th ...
分类:
其他好文 时间:
2020-07-16 18:17:25
阅读次数:
57