LC其他
暂时没有具体的专题
你别教我打游戏
直面困难,重视过程,追求结果,淡忘过去。
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LeetCode 692. 前K个高频单词 (善用STL)
前K个高频单词class Solution {public: unordered_map<string,int> m; typedef pair<int,string> P; priority_queue<P,vector<P>,greater<P> > pq; vector<string> ans; vector<string> topKFrequent(vector<st原创 2020-06-25 10:34:57 · 295 阅读 · 0 评论 -
LeetCode 1314. 矩阵区域和 (二维前缀和模板题)
矩阵区域和class Solution {public: vector<vector<int>> s; vector<vector<int>> matrixBlockSum(vector<vector<int>>& a, int k) { int m = a.size(), n = a[0].size(); //建立二维数组的前缀和、容斥原理 s.resize(原创 2020-07-22 05:22:11 · 242 阅读 · 1 评论 -
121. 买卖股票的最佳时机 (muliset维护最大值、DP思想)
买卖股票的最佳时机DP的阶段就是天数,记录下历史最低价格,用新出现的价格更新答案,并更新历史最小值。时间复杂度:O(n)O(n)O(n)class Solution {public: int maxProfit(vector<int>& prices) { int ans = 0, m = INT_MAX; for(int i=0;i<prices.size();i++){ ans = max(ans,pri原创 2020-07-20 05:29:15 · 184 阅读 · 0 评论 -
LeetCode 面试题 16.11. 跳水板 (数学思维题)
跳水板思维题不是什么DP、搜索题class Solution {public: vector<int> divingBoard(int shorter, int longer, int k) { if(k == 0) { return vector<int>{}; } if(shorter == longer) { return vector<int> {sho原创 2020-07-08 11:59:29 · 152 阅读 · 0 评论 -
LeetCode 781. 森林中的兔子 (思维、数学)
森林中的兔子这个有点像坐船问题哈。class Solution {public: int numRabbits(vector<int>& a) { int ans = 0; unordered_map<int,int> mp; for(int x:a){ mp[x+1]++; } for(auto it:mp){ int x = it.原创 2020-07-04 21:03:00 · 171 阅读 · 0 评论 -
LeetCode 205. 同构字符串(双射的构建)
同构字符串用mp存储映射fff,用rmp存储逆映射f−1f^{-1}f−1class Solution {public: bool isIsomorphic(string s, string t) { map<char,char> mp; map<char,char> rmp; for(int i=0;i<s.size();i++){ if(!mp.count(s[i])){原创 2020-07-04 16:22:18 · 210 阅读 · 0 评论 -
LeetCode 904. 水果成篮 (双指针 || 滑动窗口)
水果成篮class Solution {public: int totalFruit(vector<int>& a) { int ans = 1 , n = a.size(); int l=0,r = l+1,lr =l; while(l<n) { int x1 = a[l],x2 = -1; while(r<n && (x2==-1 || a[r]==原创 2020-06-30 20:43:40 · 2163 阅读 · 2 评论 -
LeetCode 763. 划分字母区间
划分字母区间对当前的字符,遍历找到它最后一次出现的位置,但是这个区间的长度可能小于最终长度——要对这个区间出现的字符一一进行查找它最后一次出现的地方,并用这个去更新区间长度,直到这个区间内所有的字符都满足要求。时间复杂度:O(n2)O(n^2)O(n2)class Solution {public: vector<int> partitionLabels(string S) { vector<int> ans; int n = S.si原创 2020-06-30 18:26:09 · 132 阅读 · 0 评论 -
LeetCode 463. 岛屿的周长(看懂题意就好)
岛屿的周长const int dx[] = {-1,0,1,0};const int dy[] = {0,1,0,-1};class Solution {public: int islandPerimeter(vector<vector<int>>& grid) { int ans = 0; for(int i=0;i<grid.size();i++){ for(int j=0;j<grid[原创 2020-06-23 20:39:25 · 190 阅读 · 0 评论 -
LeetCode 1023. 驼峰式匹配 (模拟、字符串、双指针)
按题目直接模拟就好,有点像双指针 ,两个字符串都只需遍历一次就好。时间复杂度:O(n∗(len1+len2))O(n*(len1+len2))O(n∗(len1+len2))为什么力扣标签是字典树呢class Solution {public: vector<bool> camelMatch(vector<string>& queries, string pattern) { vector<bool> ans; f原创 2020-06-21 16:36:00 · 235 阅读 · 0 评论 -
LeetCode 125. 验证回文串 (首尾双指针)
验证回文串 如何将string对象进行大小写字母转换。template < class InputIterator, class OutputIterator, class UnaryOperator > OutputIterator transform ( InputIterator first1, InputIterator last1, OutputIterator result, UnaryOperator op );.原创 2020-06-19 00:22:24 · 153 阅读 · 0 评论 -
LeetCode 14. 最长公共前缀(字典序、前缀树、暴力)
字典序、快排一种很巧妙的做法,虽然时间复杂度有点高。通过排序,只要比较一前一后两个字符串即可,这个两个字符串有的前缀,那么中间的所有字符串也都有这样的前缀。class Solution {public: string longestCommonPrefix(vector<string>& strs) { if(strs.size()==0){ return ""; } if(strs.size().原创 2020-06-15 12:55:03 · 345 阅读 · 0 评论
分享