上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 20 下一页
摘要: 思路 如果一个数字出现 3 次,那么它的二进制表示的每一位也出现三次,如果把所有出现三次的数字的二进制表示的每一位都分别加起来,那么每一位的和都能被 3 整除 cnt[32] 数组存储每一位 1 出现的次数 遍历数组中所有数,将其二进制表示记录在 cnt 数组里 遍历 cnt 数组,根据 cnt[i 阅读全文
posted @ 2023-05-09 14:45 穿过雾的阴霾 阅读(25) 评论(0) 推荐(0)
摘要: 思路 设两个数字分别为 x,y 将所有数字异或起来,得到的结果设为 s,s=x^y 因为相同两个数字,异或结果为 0,由于异或运算满足交换律,因此最后就剩两个数字异或 从 s 的二进制表示中,找到任意为 1 的位 k xy 的二进制表示在第 k 位上,一个是 0,一个是 1 因为 xy 不同,因此 阅读全文
posted @ 2023-05-08 20:10 穿过雾的阴霾 阅读(29) 评论(0) 推荐(0)
摘要: class Solution { public: int f[110],g[110];//分别表示第i个房屋偷,不偷的最大价值 int rob(vector<int>& nums) { int n=nums.size(); for(int i=1;i<=n;i++) { g[i]=max(f[i-1 阅读全文
posted @ 2023-05-08 20:03 穿过雾的阴霾 阅读(19) 评论(0) 推荐(0)
摘要: class Solution { public: int f[1010][1010];//f[i][j]表示s[i~j]之间的最长序列 int INF=0x3f3f3f3f; int longestPalindromeSubseq(string s) { int n=s.size(); s=' '+ 阅读全文
posted @ 2023-05-07 20:02 穿过雾的阴霾 阅读(12) 评论(0) 推荐(0)
摘要: class Solution { public: bool res=true; int dfs(TreeNode* root)//返回以root为根节点的子树深度 { if(root==NULL) return 0; int l=dfs(root->left),r=dfs(root->right); 阅读全文
posted @ 2023-05-07 17:01 穿过雾的阴霾 阅读(8) 评论(0) 推荐(0)
摘要: class Solution { public: int treeDepth(TreeNode* root) { if(!root) return 0; return max(treeDepth(root->left),treeDepth(root->right))+1; } }; 阅读全文
posted @ 2023-05-07 17:01 穿过雾的阴霾 阅读(22) 评论(0) 推荐(0)
摘要: class Solution { public: TreeNode* res=NULL; void mid(TreeNode* root, int k,int &cnt) { if(!root) return; mid(root->left,k,cnt); cnt++; if(cnt==k) res 阅读全文
posted @ 2023-05-07 17:00 穿过雾的阴霾 阅读(15) 评论(0) 推荐(0)
摘要: class Solution { public: int getNumberSameAsIndex(vector<int>& nums) { int n=nums.size(); int l=0,r=n-1; while(l<r) { int mid=l+r>>1; if(nums[mid]<mid 阅读全文
posted @ 2023-05-06 18:53 穿过雾的阴霾 阅读(19) 评论(0) 推荐(0)
摘要: class Solution { public: int f[1010][1010];//f[i][j]表示s1的下标i结尾,s2下标j结尾的最长公共子数组长度 int findLength(vector<int>& nums1, vector<int>& nums2) { int n=nums1. 阅读全文
posted @ 2023-05-06 17:12 穿过雾的阴霾 阅读(16) 评论(0) 推荐(0)
摘要: 思路 任何时刻,某个石头的重量永远都是若干石头加减运算的绝对值 如 a-b+c 合并石头都是减法,但仍可能出现+运算符,如 a-(b-c)=a-b+c 任何一种合并方法,最后一个石头的重量都可以表示成一种代数形式,如 a+b-c+d+e+f-g 不是所有的代数形式都可以转换为一种合并方法,如 a+b 阅读全文
posted @ 2023-05-05 14:04 穿过雾的阴霾 阅读(30) 评论(0) 推荐(0)
上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 20 下一页