堆,一种非常重要的数据结构。能实现数据的自动排序,而且排序时间复杂度为O(nlogn),在n达到10^4时,O(n2)级算法就容易超时,但堆排序不会。堆可调用STL系统函数,简化代码,容易书写。一般情况,如果堆元素为数、字符、字符串都可有用默认的排序规则。如果元素是pair类型,其比较大小的方式为先 ...
分类:
其他好文 时间:
2020-04-26 01:37:44
阅读次数:
78
Nastya and CBS A string $s$ is given. It consists of $k$ kinds of pairs of brackets. Each bracket has the form $t$ — it is an integer, such that $1 \l ...
分类:
其他好文 时间:
2020-04-25 12:38:47
阅读次数:
74
class Solution { public int reversePairs(int[] nums) { int len = nums.length; if(len<2){ return 0; } int[] copy = new int[len]; for(int i=0;i<len;i++) ...
分类:
编程语言 时间:
2020-04-25 01:23:49
阅读次数:
82
Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can be determined by a given pair of postorder and ino ...
分类:
其他好文 时间:
2020-04-24 13:10:38
阅读次数:
61
1 class Twitter 2 { 3 public: 4 unordered_map<int,priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>> u;//用户 -> (出现的次数,推文) 小根堆 ...
分类:
其他好文 时间:
2020-04-22 23:00:19
阅读次数:
114
报错: 类Pair是公共的, 应在名为 Pair.java 的文件中声明这说明我们的Public 类名和文件名没有保持一致。1.每一个.java文件可以有多个类,但是这能有一个public class2.public class 的类名必须和文件名保持一直,要不然没有办法进行编译。 ...
分类:
其他好文 时间:
2020-04-22 16:33:14
阅读次数:
50
使用泛型的优缺点: 优点:避免了类型转换的的麻烦,存储什么类型,取出什么类型;把运行异常,提升到了编译期 缺点:只能存储单一类型 泛型就是编写模板代码来适应任意类型 不必对类型进行强制转换 编译器将对类型进行检查 注意泛型的继承关系: 可以把ArrayList<Integer>向上转型为List<I ...
分类:
编程语言 时间:
2020-04-22 16:20:01
阅读次数:
74
Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can be determined by a given pair of postorder and ino ...
分类:
其他好文 时间:
2020-04-22 12:51:03
阅读次数:
65
给定一棵二叉树,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。示例:输入: [1,2,3,null,5,null,4]输出: [1, 3, 4]解释: 1 rightSideView(TreeNode* root) { vector ans; if(root==NULL)... ...
分类:
其他好文 时间:
2020-04-22 09:54:24
阅读次数:
52
题目描述 Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the ...