优先队列基本介绍 优先队列又叫做堆,他是一种比较特殊的完全二叉树。所谓完全二叉树就是一层层的堆叠,本层不满就不能堆放下一层。并且优先队列还有一个特点就是如果他是大根堆那么父节点不小于子节点,如果是小根堆父节点不大于子节点。这也是一个递归定义。 为什么要是用优先队列? 首先如果我们需要查找一个第 k 大的数字,毫无疑问这个是最方便的 他的插入操作和删除操作都是 logn 的复杂度,所以说他是最经济的方式 优先队列的常用操作插入插入的时候我们一般采用的方式就是上滤,也就是把要插入的...
HouseRobber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will a...
IntersectionOfTwoLinkedLists
Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: A: a1 → a2 ↘ c1 → c2 → c3 ↗ B: b...
LinkedListCycle
Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? 分析 一开始使用了复杂度O(n^2)的方法,使用两个指针a, b。a从表头开始一步一步往前走,遇到null则说明没有环,返回false;a每走一步,b从头开始走,如果遇到b==a.next,则说明有环true,如果遇到b==a,则说明暂时没有环,继续循环。 后来找...