随笔分类 - leetcode
摘要:题面: 题解:单调栈 代码: class Solution { public: string removeDuplicateLetters(string s) { int n = s.size(); vector<int> num(26,0),vis(26,0); string stk; for(i
阅读全文
摘要:题面: 题解:前缀10字典序比2小,因此这个类似于类似于求前缀和。函数getnum(pre,n)求前缀pre为根结点的前缀和的数量。pre=1开始,如果当前节点的子节点数量大于k则pre*=10,否则 pre++。 代码: class Solution { public: int getnum(lo
阅读全文
摘要:题面: 题解:按照拓扑序即可。 代码: class Solution { public: string alienOrder(vector<string>& words) { int n = words.size(); string ans=""; unordered_map<char, unord
阅读全文
摘要:题面: 题解: 双指针找区间即可。 代码: class Solution { public: int numberOfSubstrings(string s) { int numa = 0,numb = 0,numc = 0,l = 0,r = 0; int n = s.size(); int an
阅读全文
摘要:题面: 题解:bfs即可,不过要注意判重,相同值的加入一次即可。 代码: class Solution { public: int minJumps(vector<int>& arr) { map< int, vector<int> >ma; queue<pair<int, int> >q; int
阅读全文
摘要:题面: 题解:维护长度为p的长度的滑动窗口,cnts维护当前窗口内个字母s与p的差,用一个变量res维护不同的数量,当res=0时是异位词。 class Solution { public: int cnts[26]; int cntp[26]; vector<int> findAnagrams(s
阅读全文
摘要:题面: 样例: 题解:暴力搜索,加上相等剪枝。 代码: class Solution { public: int n,m; int k; int dx[4]={-1,1,0,0}; int dy[4]={0,0,-1,1}; int vis[205][205]; vector<vector<char
阅读全文
摘要:题面: 题解:从小到大排序,取相邻的最小差即可。 代码: class Solution { public: int findMinDifference(vector<string>& t) { vector<int>res; int n=t.size(); if(n>1440)return 0; f
阅读全文
摘要:题面: 样例: 题解: dp[i][j] 表示前i个字符当最后一个字符为【a=0,e=1,i=2,o=3,u=4】时的数量,转移方程易得。 代码: class Solution { public:int long long dp[20010][5]; int mod=1e9+7; int count
阅读全文
摘要:题面: 给出基数为 -2 的两个数 arr1 和 arr2,返回两数相加的结果。 数字以 数组形式 给出:数组由若干 0 和 1 组成,按最高有效位到最低有效位的顺序排列。例如,arr = [1,1,0,1] 表示数字 (-2)^3 + (-2)^2 + (-2)^0 = -3。数组形式 的数字也同
阅读全文
摘要:题意: 给你一份工作时间表 hours,上面记录着某一位员工每天的工作小时数。 我们认为当员工一天中的工作小时数大于 8 小时的时候,那么这一天就是「劳累的一天」。 所谓「表现良好的时间段」,意味在这段时间内,「劳累的天数」是严格 大于「不劳累的天数」。 请你返回「表现良好时间段」的最大长度。 示例
阅读全文
摘要:题面: 作为项目经理,你规划了一份需求的技能清单 req_skills,并打算从备选人员名单 people 中选出些人组成一个「必要团队」( 编号为 i 的备选人员 people[i] 含有一份该备选人员掌握的技能列表)。 所谓「必要团队」,就是在这个团队中,对于所需求的技能列表 req_skill
阅读全文

浙公网安备 33010602011771号