当前位置:首页 > 编程笔记 > 正文
已解决

力扣371周赛

来自网友在路上 163863提问 提问时间:2023-11-12 14:29:12阅读次数: 63

最佳答案 问答题库638位专家为你答疑解惑

力扣第371场周赛

找出强数对的最大异或值 I

枚举

class Solution {
public:int maximumStrongPairXor(vector<int>& a) {int n = a.size() , res = 0;for(int i = 0 ; i < n ; i ++){for(int j = 0 ; j < n ; j ++){if(abs(a[i]-a[j])<=min(a[i],a[j])){int c = (a[i]^a[j]);res = max(res , c);}}}return res;}
};

高访问员工

排序后模拟枚举每个点模拟一下

class Solution {
public:vector<string> findHighAccessEmployees(vector<vector<string>>& as) {unordered_map<string,vector<string>>mp;vector<string>ans;int n = as.size();for(int i = 0 ; i < n ; i ++){mp[as[i][0]].push_back(as[i][1]);}for(auto x: mp){string c = x.first;vector<string>tmp = x.second;int m = tmp.size();if(m < 3)continue;ranges::sort(tmp);for(int i = 1 ; i < m - 1; i ++){int last=stoi(tmp[i-1]);int cur = stoi(tmp[i]);int next=stoi(tmp[i+1]);if(abs(cur - last) < 100 && abs(next - cur) < 100 && abs(next - last) < 100){ans.push_back(c);break;}}}return ans;}
};

最大化数组末位元素的最少操作次数

枚举一下最后一个要不要交换

class Solution {
public:int check(int a ,int b ,int c1 ,int c2){if((a <= c1) && (b<=c2))return 0;if(a > c1){if(a > c2)return -1;if(b > c1)return -1;return 1;}if(b > c2){if(b > c1)return -1;if(a > c2)return -1;return 1;}return 0;}int minOperations(vector<int>& nums1, vector<int>& nums2) {int ans1 = 0,ans2 = 1, n = nums1.size();int c1 = 0 , c2 = 0;bool f1 = true , f2 = true;c1 = nums1[n-1],c2=nums2[n-1];for(int i = n - 2 ; i >= 0 ; i --){int s = check(nums1[i],nums2[i],c1,c2);if(s == -1){f1 = false;break;}ans1 += s;}c1 = nums2[n-1],c2=nums1[n-1];for(int i = n - 2 ; i >= 0 ; i --){int s = check(nums1[i],nums2[i],c1,c2);if(s == -1){f2 = false;break;}ans2+=s;}if(f1 && f2){return min(ans1,ans2);}if(f1 == true && f2 == false)return ans1;if(f1 == false && f2 == true)return ans2;return -1;}
};

找出强数对的最大异或值 II

补题ing

查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"力扣371周赛":http://eshow365.cn/6-38145-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!