二叉树的遍历、非递归实现 public class TreeNode{ int val; TreeNode left; TreeNode right; TreeNode(int val){ this.val = val; }}一、二叉树的前序遍历//非递归实现public void preOrder(TreeNode root){ if(root == null) return; Stack<TreeNode> stack = n.
海量数据获取TopK、堆排序,快速排序实现 注意:最小TopK用大顶堆,最大TopK用小顶堆一、用java 的priorityQueue实现//最小Top, 用java的PriorityQueueimport java.util.*;public class Solution{ public ArrayList<Integer<> getLeastNumber_Solution(int[] input, int k){ int n = input.length; ArrayLis
LRU 缓存的两种实现方式 LRU 缓存的两种实现方式一、使用LinkedHashMap实现class LRUCache { Map<Integer, Integer> cache=null; public LRUCache(int capacity) { cache = new LinkedHashMap<>(capacity, 0.75f, true){ @Override public boolean remov
数据和函数 数据和函数 1、枚举类型Inductive day : Type := | monday : day | tuesday : day | wednesday : day | thursday : day | friday : day | saturday : day | sunday : day. 上面的例子定义了一个 day 的类型,...
Animation 动画 Animation 动画 1、定义方程使用matplotlib做动画也是可以的,我们使用其中一种方式,function animation来说说, 具体可参考matplotlib animation api。首先,我们做一些准备工作:from matplotlib import pyplot as pltfrom matplotlib import animatio...
次坐标轴 次坐标轴 1、第一个y坐标有时候我们会用到次坐标轴,即在同个图上有第2个y轴存在。同样可以用matplotlib做到,而且很简单。import matplotlib.pyplot as pltimport numpy as npx = np.arange(0, 10, 0.1)y1 = 0.05 * x**2y2 = -1 * y1可以看到,y2和y...
图中图 图中图 1、数据# 导入pyplot模块import matplotlib.pyplot as plt# 初始化figurefig = plt.figure()# 创建数据x = [1, 2, 3, 4, 5, 6, 7]y = [1, 3, 4, 2, 5, 8, 6]2、大图接着,绘制大图。首先确定大图左下角的位置以及宽高:left, bo...
Subplot 分格显示 Subplot 分格显示 1、subplot2grid使用import导入matplotlib.pyplot模块, 并简写成plt. 使用plt.figure()创建一个图像窗口import matplotlib.pyplot as pltplt.figure()使用plt.subplot2grid来创建第1个小图, (3,3)表示将整个图像窗口分成3行3列,...
Subplot 多合一显示 Subplot 多合一显示 1、均匀图中图matplotlib 是可以组合许多的小图, 放在一张大图里面显示的. 使用到的方法叫作 subplot.使用import导入matplotlib.pyplot模块, 并简写成plt. 使用plt.figure创建一个图像窗口.import matplotlib.pyplot as pltplt.figure()使用...