
位运算
matt__
这个作者很懒,什么都没留下…
展开
-
leetcode 421. 数组中两个数的最大异或值
//然后再对每个数的异或值进行比较; class Solution { public: struct Node { int son[2]; }; vector<Node>nodes; int findMaximumXOR(vector<int>& nums) { nodes.pu...翻译 2019-07-30 22:22:20 · 345 阅读 · 0 评论 -
leetcode 477. 汉明距离总和
class Solution { public: int totalHammingDistance(vector<int>& nums) { int res=0; for(int i=0;i<=30;i++)//位数 { int rec=0; for(auto p:nums...翻译 2019-07-30 22:24:59 · 210 阅读 · 0 评论 -
leetcode 201. 数字范围按位与
class Solution { public: int rangeBitwiseAnd(int m, int n) { int rec=0; for(int i=0;m!=n;i++) { m>>=1; n>>=1;//把两个数字同时右移,如果最高位位数相同就会留下最高为,如果...翻译 2019-07-30 22:41:41 · 134 阅读 · 0 评论 -
leetcode 260. 只出现一次的数字 III
class Solution { public: vector<int> singleNumber(vector<int>& nums) { int res=0,rec=0,k=0; for(auto p:nums) res^=p;//res存储的是此时两个单独的数的异或值; while(!(res>>...翻译 2019-07-30 22:47:15 · 212 阅读 · 0 评论