
堆
我,秦始皇的爷爷,打钱
道阻且长,行则将至
展开
-
LeetCode刷题记205-Heap(堆)
215. 数组中的第K个最大元素class Solution { public void swap(int[] a, int i, int j) { int tmp = a[i]; a[i] = a[j]; a[j] = tmp; } public void buildMaxHeap(int[] a, int i, int length) { int l = (i << 1) + 1; in原创 2021-03-23 11:57:37 · 87 阅读 · 0 评论 -
LeetCode刷题记156-407. 接雨水 II【再做一遍】
LeetCode刷题记156407. 接雨水 II题目class Solution { public int trapRainWater(int[][] heightMap) { class MyComparator implements Comparator<Pair<Integer, Integer>> { @Override public int compare(Pair<Integer,原创 2020-12-22 11:14:33 · 98 阅读 · 0 评论 -
LeetCode刷题记155-239. 滑动窗口最大值
LeetCode刷题记155239. 滑动窗口最大值题目class Solution { public int[] maxSlidingWindow(int[] nums, int k) { PriorityQueue<Integer> pq = new PriorityQueue<Integer>((a, b) -> b - a); // 存值,大的在前面 int[] cnt = new int[20005]; // 存值原创 2020-12-21 16:12:51 · 134 阅读 · 0 评论 -
LeetCode刷题记154-218. 天际线问题【再做一遍】
LeetCode刷题记15484. 柱状图中最大的矩形题目class Solution { public int largestRectangleArea(int[] heights) { if (heights.length == 0) return 0; int[] sta = new int[heights.length]; //模拟栈,记录下标,这里存的高度是严格递增的 int top = -1; int ans =原创 2020-12-21 16:10:41 · 134 阅读 · 1 评论