04 2023 档案

摘要:class Solution { public: //二分找出k第一次,最后一个k后面的下标,相减就是答案 int getNumberOfK(vector<int>& nums , int k) { int n=nums.size(); if(!n) return 0; //找到第一个≥k的下标 i 阅读全文
posted @ 2023-04-28 15:19 穿过雾的阴霾 阅读(12) 评论(0) 推荐(0) 编辑
摘要:使用空间存储节点的解法 class Solution { public: set<ListNode*> s; ListNode *findFirstCommonNode(ListNode *headA, ListNode *headB) { for (auto i = headA; i ; i=i- 阅读全文
posted @ 2023-04-28 14:47 穿过雾的阴霾 阅读(11) 评论(0) 推荐(0) 编辑
摘要:class Solution{ public: string str; int i=0; int cnt[256]={0}; //Insert one char from stringstream void insert(char c){ str+=c; cnt[c]++; } //return t 阅读全文
posted @ 2023-04-27 15:00 穿过雾的阴霾 阅读(11) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int longestSubstringWithoutDuplication(string s) { int len=0,n=s.size(),cnt[30]; memset(cnt,0,sizeof cnt); for (int i = 0,j = 阅读全文
posted @ 2023-04-27 14:06 穿过雾的阴霾 阅读(9) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int f[510][510];//f[i][j]表示将s1前i个字符和s2前j个字符的最长公共子序列长度 int minDistance(string word1, string word2) { int n=word1.size(),m=word 阅读全文
posted @ 2023-04-26 17:13 穿过雾的阴霾 阅读(11) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: bool check(char a,char b) { int num=(a-'0')*10+(b-'0'); if(num>=10&&num<=25) return true; return false; } int getTranslationC 阅读全文
posted @ 2023-04-26 16:37 穿过雾的阴霾 阅读(17) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int res; priority_queue<int,vector<int>,greater<int>> minheap; unordered_set<int> s;//所有出现过的丑数放在集合中 int getUglyNumber(int n) 阅读全文
posted @ 2023-04-25 15:08 穿过雾的阴霾 阅读(12) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int f[60];//f[i]记录i能拆出的最大乘积 int integerBreak(int n) { for(int i=2;i<=n;i++) for(int j=1;j<i;j++)//枚举最后一个拆出的数字,这里不能只循环到i/2 f[i 阅读全文
posted @ 2023-04-24 16:28 穿过雾的阴霾 阅读(11) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: long long f[1010];//f[i]表示总和为i的选法个数 int combinationSum4(vector<int>& nums, int target) { int n=nums.size(); f[0]=1; for(int i 阅读全文
posted @ 2023-04-24 15:43 穿过雾的阴霾 阅读(10) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int getMaxValue(vector<vector<int>>& grid) { int n=grid.size(),m=grid[0].size(); vector<vector<int>> f(n,vector<int> (m,0));/ 阅读全文
posted @ 2023-04-24 14:50 穿过雾的阴霾 阅读(13) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: static bool cmp(int a,int b) { string as=to_string(a),bs=to_string(b); return as+bs<bs+as; } string printMinNumber(vector<int 阅读全文
posted @ 2023-04-23 15:46 穿过雾的阴霾 阅读(8) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int digitAtIndex(int n) { if(!n) return 0; long long start=1,len=1,cnt=1;//记录区间的起始位置,记录区间长度,cnt记录当前是几位数 //往后走,跨度为一个区间 while(1 阅读全文
posted @ 2023-04-21 14:57 穿过雾的阴霾 阅读(11) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int numberOf1Between1AndN_Solution(int n) { vector<int> q; do { q.push_back(n%10); n/=10; }while(n); int res=0; for (int i = 阅读全文
posted @ 2023-04-20 11:12 穿过雾的阴霾 阅读(15) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int maxSubArray(vector<int>& nums) { int n=nums.size(),res=-0x3f3f3f3f; for (int i = 0; i < n;)//枚举以i为起点的区间 { int j=i,sum=0; 阅读全文
posted @ 2023-04-19 16:50 穿过雾的阴霾 阅读(10) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: priority_queue<int> max_heap; priority_queue<int,vector<int>,greater<int>> min_heap; void insert(int num){ max_heap.push(num) 阅读全文
posted @ 2023-04-19 16:13 穿过雾的阴霾 阅读(11) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: bool f[310]; bool wordBreak(string s, vector<string>& wordDict) { unordered_set<string> hashtable; for(auto i:wordDict) hasht 阅读全文
posted @ 2023-04-18 16:11 穿过雾的阴霾 阅读(17) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: bool check(string s) { int n=s.size(); for(int i=0;i<n/2;i++) if(s[i]!=s[n-i-1]) return false; return true; } vector<vector<s 阅读全文
posted @ 2023-04-16 11:18 穿过雾的阴霾 阅读(4) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector<vector<int>> res; vector<int> path; bool st[10]; void dfs(vector<int>& nums,int u) { int n=nums.size(); if(u==n) { res 阅读全文
posted @ 2023-04-15 20:31 穿过雾的阴霾 阅读(11) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int moreThanHalfNum_Solution(vector<int>& nums) { int cnt=0,val=-1;//val给一个无效值即可 for(auto x:nums) { if(!cnt)//投票最多人没了,接下来任何人都 阅读全文
posted @ 2023-04-15 20:31 穿过雾的阴霾 阅读(15) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: long long f[1010][1010];//f[i][j]表示s前i个字符得到t前j个字符的所有方案 int numDistinct(string s, string t) { f[0][0]=1; int n=s.size(),m=t.si 阅读全文
posted @ 2023-04-15 14:29 穿过雾的阴霾 阅读(11) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int f[25][2010];//体积范围从-1000~1000 int findTargetSumWays(vector<int>& nums, int target) { int n=nums.size(),offset=1000;//价值总和 阅读全文
posted @ 2023-04-14 20:54 穿过雾的阴霾 阅读(14) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: bool f[110][110]; bool isInterleave(string s1, string s2, string s3) { int n=s1.size(),m=s2.size(); if(n+m!=s3.size()) return 阅读全文
posted @ 2023-04-14 19:45 穿过雾的阴霾 阅读(11) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int f[25];//f[i]表示i个数可以构成的树的个数 int numTrees(int n) { f[0]=1; for(int i=1;i<=n;i++) { for(int j=1;j<=i;j++)//以j为根节点 f[i]+=f[j- 阅读全文
posted @ 2023-04-13 17:03 穿过雾的阴霾 阅读(7) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: TreeNode* pre=NULL; void dfs(TreeNode* root) { if(!root) return; dfs(root->left); root->left=pre; if(pre) pre->right=root; pr 阅读全文
posted @ 2023-04-12 18:45 穿过雾的阴霾 阅读(15) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int f[110]; bool check(char a,char b) { if(a>='1'&&a<='9'&&b>='0'&&b<='9') { int c=a-'0'; c=c*10+(b-'0'); if(c>=1&&c<=26) ret 阅读全文
posted @ 2023-04-12 16:26 穿过雾的阴霾 阅读(11) 评论(0) 推荐(0) 编辑
摘要:/* // Definition for a Node. class Node { public: int val; Node* next; Node* random; Node(int _val) { val = _val; next = NULL; random = NULL; } }; */ 阅读全文
posted @ 2023-04-04 15:12 穿过雾的阴霾 阅读(11) 评论(0) 推荐(0) 编辑
摘要:暴力做法 时间复杂度 O (n^2) 遍历一遍,复制 next 指针,新建链表 遍历第二遍,复制 random 指针,查找每一个 random 节点的位置 class Solution { public: ListNode *copyRandomList(ListNode *head) { List 阅读全文
posted @ 2023-04-04 11:21 穿过雾的阴霾 阅读(15) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int method(vector<int> h)//求柱状图中最大的矩形 { int n=h.size(); vector<int> l=vector<int> (n),r=l; stack<int> st; //预处理l,r数组 for(int 阅读全文
posted @ 2023-04-01 11:16 穿过雾的阴霾 阅读(12) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector<vector<int>> res; vector<int> path; void dfs(TreeNode* root, int sum,int t) { t+=root->val; path.push_back(root->val); 阅读全文
posted @ 2023-04-01 09:55 穿过雾的阴霾 阅读(10) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: bool dfs(vector<int> q,int l,int r) { if(l>=r) return true; int root=q[r]; int idx=l; for (; idx < r; idx ++ ) if(q[idx]>root 阅读全文
posted @ 2023-04-01 09:20 穿过雾的阴霾 阅读(13) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示