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
1 class Solution 2 { 3 public: 4 vector<int> topKFrequent(vector<int>& nums, int k) 5 { 6 vector<int> res; 7 unordered_map<int,int> hash; 8 for(auto a ...
分类:
其他好文 时间:
2020-04-22 19:38:30
阅读次数:
43
1 class Solution 2 { 3 public: 4 void reverseString(vector<char>& s) 5 { 6 int n = s.size(); 7 for(int i = 0;i < n/2;i ++) swap(s[i],s[n - i - 1]); 8 ...
分类:
其他好文 时间:
2020-04-22 19:35:57
阅读次数:
50
leetcode "199. 二叉树的右视图" 因为某些比赛导致三天没写编程题,回来之后发现自己好像啥都不会了,写每一题都要花费好长时间/_ \ 牢骚结束:二叉树的遍历一般用dfs或者bfs,dfs一般用于前中后序遍历,bfs一般用于层序遍历 方法一:这一题最直观的解法就是得到二叉树的层序遍历,然后 ...
分类:
其他好文 时间:
2020-04-22 16:17:55
阅读次数:
61
1. clear() 将整个 vector 都删除 使用 vectorname.clear() 可以将整个vector 中的元素全部删除,但是内存不会释放,如下代码: 1 #include <iostream> 2 #include <vector> 3 4 using namespace std; ...
分类:
其他好文 时间:
2020-04-22 10:02:16
阅读次数:
56
给定一棵二叉树,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。示例:输入: [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 ...
1 //空节点的个数 = 非空节点个数 + 1 2 class Solution 3 { 4 vector<string> res; 5 void spilt(string s,char c) 6 { 7 istringstream iss(s); 8 string temp; 9 while(ge ...
分类:
其他好文 时间:
2020-04-21 22:26:34
阅读次数:
87
题目描述: 给你一个由 '1'(陆地)和 '0'(水)组成的的二维网格,请你计算网格中岛屿的数量。 岛屿总是被水包围,并且每座岛屿只能由水平方向和/或竖直方向上相邻的陆地连接形成。 此外,你可以假设该网格的四条边均被水包围。 示例 1: 输入:11110110101100000000输出: 1示例 ...
分类:
其他好文 时间:
2020-04-21 12:38:00
阅读次数:
59