上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 20 下一页
摘要: ``` class Solution { public: vector t; void dfs(TreeNode* root,TreeNode* p,vector &q) { if(!root) return; t.push_back(root); if(root==p) { q=t; t.pop_ 阅读全文
posted @ 2023-05-19 15:16 穿过雾的阴霾 阅读(21) 评论(0) 推荐(0)
摘要: 模拟计算机的加法器实现 * x存放不进位的加法结果,y存放进位。不进位的结果加上进位就是答案,换句话就是x+y * 不进位加法结果可以通过异或实现,两数相加的进位可以通过逻辑与,再左移一位实现 * 计算x+y,又是重复上面的步骤,循环即可,直到进位为0,循环结束 ``` class Solution 阅读全文
posted @ 2023-05-19 14:40 穿过雾的阴霾 阅读(22) 评论(0) 推荐(0)
摘要: class Solution { public: bool check(char c) { if(c=='+') return true; if(c=='-') return true; if(c>='0'&&c<='9') return true; return false; } int strT 阅读全文
posted @ 2023-05-18 20:57 穿过雾的阴霾 阅读(19) 评论(0) 推荐(0)
摘要: class Solution { public: int getSum(int n) { int res=n; //if(n>0) res+=getSum(n-1); (res>0)&&(res+=getSum(n-1)); return res; } }; 阅读全文
posted @ 2023-05-18 20:35 穿过雾的阴霾 阅读(17) 评论(0) 推荐(0)
摘要: class Solution { public: int q[4010]; bool notexist[4010]; void move(int &j,int n)//后移 { do { j++; j=j%n; } while(notexist[j]!=false); } int lastRemai 阅读全文
posted @ 2023-05-18 20:06 穿过雾的阴霾 阅读(16) 评论(0) 推荐(0)
摘要: class Solution { public: string longestPalindrome(string s) { string res; int n=s.size(); for(int i=0;i<n;i++) { //长度是奇数 int l=i-1,r=i+1; while(l>=0&& 阅读全文
posted @ 2023-05-16 20:25 穿过雾的阴霾 阅读(9) 评论(0) 推荐(0)
摘要: 可以直接分类讨论,分别枚举第一个房屋偷或不偷的情况,最后再取极值 不偷第一家 f[i] 代表前 i 个房屋,偷第 i 个, 且不偷第一家的最大值 g[i] 代表前 i 个房屋,不偷第 i 个, 且不偷第一家的最大值 偷第一家 f[i] 代表前 i 个房屋,偷第 i 个, 且偷第一家的最大值 g[i] 阅读全文
posted @ 2023-05-15 14:00 穿过雾的阴霾 阅读(23) 评论(0) 推荐(0)
摘要: class Solution { public: bool isContinuous( vector<int> q ) { if(q.empty()) return false; sort(q.begin(),q.end()); int zero=0,n=q.size(); for (int i = 阅读全文
posted @ 2023-05-15 13:07 穿过雾的阴霾 阅读(31) 评论(0) 推荐(0)
摘要: ```c class Solution { public: vector<int> res; vector<int> numberOfDice(int n) { vector<vector<int> >f(n+1,vector<int>(6*n+1));//f[i][j]表示选了i个数,和为j的所有 阅读全文
posted @ 2023-05-14 15:05 穿过雾的阴霾 阅读(62) 评论(0) 推荐(0)
摘要: class Solution { public: int maxProfit(vector<int>& prices) { int n=prices.size(); vector<int> f(n+1),g(n+1); //预处理f,f[i]表示前i天交易的最大值 for(int i=1,min_p 阅读全文
posted @ 2023-05-14 15:04 穿过雾的阴霾 阅读(20) 评论(0) 推荐(0)
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 20 下一页