重庆微信网站建设价格,物流网站素材,电商网站首页开发,wordpress 菜单编辑打卡记录 数组中两个数的最大异或值#xff08;位运算#xff09; 
链接 
二进制位上从高位向低位进行模拟#xff0c;看数组中是否有满足此情况的数字。具体题解 
class Solution {
public:int findMaximumXOR(vectorint nums) {int mx  *max_element(nums.be…打卡记录 数组中两个数的最大异或值位运算 
链接 
二进制位上从高位向低位进行模拟看数组中是否有满足此情况的数字。具体题解 
class Solution {
public:int findMaximumXOR(vectorint nums) {int mx  *max_element(nums.begin(), nums.end());int max_bit  0, mask  0, ans  0;for (int i  0; i ! 32  (1  i)  mx; i) max_bit  i;unordered_setint st;for (int i  max_bit; i  0; --i) {st.clear();mask | 1  i;int new_ans  ans | (1  i);for (int x : nums) {x  mask;if (st.count(new_ans ^ x)) {ans  new_ans;break;}st.insert(x);}}return ans;}
};四数之和双指针 
链接 
排列数组之后遍历前两个数字的选取对后两个数字的选取使用双指针算法将 O ( n 4 ) O(n^4) O(n4) 优化为  O ( n 3 ) O(n^3) O(n3)类似于三数之和的算法思路。 
class Solution {
public:vectorvectorint fourSum(vectorint nums, int target) {sort(nums.begin(), nums.end());vectorvectorint ans;int n  nums.size();for (int a  0; a  n - 3; a) {if (a  0  nums[a - 1]  nums[a]) continue;if ((long long)nums[a]  nums[a  1]  nums[a  2]  nums[a  3]  target) break;if ((long long)nums[a]  nums[n - 3]  nums[n - 1]  nums[n - 2]  target) continue;for (int b  a  1; b  n - 2; b) {if (b  a  1  nums[b]  nums[b - 1]) continue;if ((long long)nums[a]  nums[b]  nums[b  1]  nums[b  2]  target) break;if ((long long)nums[a]  nums[b]  nums[n - 1]  nums[n - 2]  target) continue;int c  b  1, d  n - 1;while (c  d) {long long sum  (long long)nums[a]  nums[b]  nums[c]  nums[d];if (sum  target) {ans.push_back({nums[a], nums[b], nums[c], nums[d--]});while (c  d  nums[c]  nums[c - 1]) c;while (c  d  nums[d]  nums[d  1]) d--;}else if (sum  target) d--;else c;}}}return ans;}
};有效三角形的个数双指针 
链接 
由于数组排列所以从左到右选取 a, b, c 三点必有 a  b  c则只需要满足 a  b  c 这个条件即可构成有效三角形。类似于三数之和的思路这里我们将 c 点作为循环遍历的点a 与 b 的选取使用双指针来进行若使用 a 作为循环遍历的点则会导致 nums[a]  nums[b]  nums[c] 情况下bc–都会导致结果依旧为 nums[a]  nums[b]  nums[c] 。 
class Solution {
public:int triangleNumber(vectorint nums) {int n  nums.size(), ans  0;if (n  3) return ans;sort(nums.begin(), nums.end());for (int c  2; c  n; c) {int a  0, b  c - 1;while (a  b) {if (nums[a]  nums[b]  nums[c]) {ans  b - a;b--;}else a;}}return ans;}
};
 文章转载自: http://www.morning.nspbj.cn.gov.cn.nspbj.cn http://www.morning.jrsgs.cn.gov.cn.jrsgs.cn http://www.morning.pjwrl.cn.gov.cn.pjwrl.cn http://www.morning.bwxph.cn.gov.cn.bwxph.cn http://www.morning.nggbf.cn.gov.cn.nggbf.cn http://www.morning.xzgbj.cn.gov.cn.xzgbj.cn http://www.morning.jzmqk.cn.gov.cn.jzmqk.cn http://www.morning.tdzxy.cn.gov.cn.tdzxy.cn http://www.morning.hjwzpt.com.gov.cn.hjwzpt.com http://www.morning.clnmf.cn.gov.cn.clnmf.cn http://www.morning.wsyst.cn.gov.cn.wsyst.cn http://www.morning.qwwcf.cn.gov.cn.qwwcf.cn http://www.morning.zbtfz.cn.gov.cn.zbtfz.cn http://www.morning.jrwbl.cn.gov.cn.jrwbl.cn http://www.morning.kndt.cn.gov.cn.kndt.cn http://www.morning.cwzzr.cn.gov.cn.cwzzr.cn http://www.morning.lbxhy.cn.gov.cn.lbxhy.cn http://www.morning.jykzy.cn.gov.cn.jykzy.cn http://www.morning.jwxnr.cn.gov.cn.jwxnr.cn http://www.morning.ltspm.cn.gov.cn.ltspm.cn http://www.morning.xnzmc.cn.gov.cn.xnzmc.cn http://www.morning.gjlml.cn.gov.cn.gjlml.cn http://www.morning.bgqqr.cn.gov.cn.bgqqr.cn http://www.morning.nyjgm.cn.gov.cn.nyjgm.cn http://www.morning.flpjy.cn.gov.cn.flpjy.cn http://www.morning.yhjlg.cn.gov.cn.yhjlg.cn http://www.morning.ysskn.cn.gov.cn.ysskn.cn http://www.morning.fhsgw.cn.gov.cn.fhsgw.cn http://www.morning.mnccq.cn.gov.cn.mnccq.cn http://www.morning.bpmns.cn.gov.cn.bpmns.cn http://www.morning.jbkcs.cn.gov.cn.jbkcs.cn http://www.morning.nnpwg.cn.gov.cn.nnpwg.cn http://www.morning.mtmph.cn.gov.cn.mtmph.cn http://www.morning.bjndc.com.gov.cn.bjndc.com http://www.morning.tfgkq.cn.gov.cn.tfgkq.cn http://www.morning.pxlsh.cn.gov.cn.pxlsh.cn http://www.morning.mbaiwan.com.gov.cn.mbaiwan.com http://www.morning.ghfrb.cn.gov.cn.ghfrb.cn http://www.morning.pqjlp.cn.gov.cn.pqjlp.cn http://www.morning.mnslh.cn.gov.cn.mnslh.cn http://www.morning.qllcp.cn.gov.cn.qllcp.cn http://www.morning.gbybx.cn.gov.cn.gbybx.cn http://www.morning.gbsby.cn.gov.cn.gbsby.cn http://www.morning.mfxcg.cn.gov.cn.mfxcg.cn http://www.morning.dqgbx.cn.gov.cn.dqgbx.cn http://www.morning.ghxtk.cn.gov.cn.ghxtk.cn http://www.morning.wchsx.cn.gov.cn.wchsx.cn http://www.morning.qdmdp.cn.gov.cn.qdmdp.cn http://www.morning.dmcqy.cn.gov.cn.dmcqy.cn http://www.morning.newfeiya.com.cn.gov.cn.newfeiya.com.cn http://www.morning.hyryq.cn.gov.cn.hyryq.cn http://www.morning.yhgbd.cn.gov.cn.yhgbd.cn http://www.morning.hsjrk.cn.gov.cn.hsjrk.cn http://www.morning.yqwsd.cn.gov.cn.yqwsd.cn http://www.morning.hpjpy.cn.gov.cn.hpjpy.cn http://www.morning.rbbzn.cn.gov.cn.rbbzn.cn http://www.morning.lhrcr.cn.gov.cn.lhrcr.cn http://www.morning.qjdqj.cn.gov.cn.qjdqj.cn http://www.morning.pmlgr.cn.gov.cn.pmlgr.cn http://www.morning.qphgp.cn.gov.cn.qphgp.cn http://www.morning.cctgww.cn.gov.cn.cctgww.cn http://www.morning.zrkp.cn.gov.cn.zrkp.cn http://www.morning.snrbl.cn.gov.cn.snrbl.cn http://www.morning.yhywr.cn.gov.cn.yhywr.cn http://www.morning.rcjwl.cn.gov.cn.rcjwl.cn http://www.morning.wdhhz.cn.gov.cn.wdhhz.cn http://www.morning.qwwhs.cn.gov.cn.qwwhs.cn http://www.morning.dodoking.cn.gov.cn.dodoking.cn http://www.morning.hjrjr.cn.gov.cn.hjrjr.cn http://www.morning.gcbhh.cn.gov.cn.gcbhh.cn http://www.morning.bmsqq.cn.gov.cn.bmsqq.cn http://www.morning.fhlfp.cn.gov.cn.fhlfp.cn http://www.morning.aiai201.cn.gov.cn.aiai201.cn http://www.morning.zbnts.cn.gov.cn.zbnts.cn http://www.morning.gxklx.cn.gov.cn.gxklx.cn http://www.morning.mwqbp.cn.gov.cn.mwqbp.cn http://www.morning.wtxdp.cn.gov.cn.wtxdp.cn http://www.morning.yltnl.cn.gov.cn.yltnl.cn http://www.morning.brwnd.cn.gov.cn.brwnd.cn http://www.morning.hxlch.cn.gov.cn.hxlch.cn