当前位置: 首页 > news >正文

力扣371周赛

力扣第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

http://www.lryc.cn/news/226969.html

相关文章:

  • Python之字符串、正则表达式练习
  • Transmit :macOS 好用的 Ftp/SFtp 工具
  • 【Github】git clone命令下载文件中途停止
  • Clickhouse学习笔记(10)—— 查询优化
  • [量化投资-学习笔记012]Python+TDengine从零开始搭建量化分析平台-策略回测
  • MySQL 查看 event 执行记录
  • 开发知识点-Vue-Electron
  • 【线性代数】反求矩阵A
  • MyBatis 中的 foreach 的用法
  • 交叉编译 mysql-connector-c
  • 企业如何选择正确的存储服务器租用?
  • 45.跳跃游戏II
  • css style、css color 转 UIColor
  • C++(20):typename声明类的子类型的简化
  • 一个java文件的JVM之旅
  • C# wpf 实现任意控件(包括窗口)更多拖动功能
  • 一种ADC采样算法,中位值平均滤波+递推平均滤波
  • 技能培训知识付费服务预约小程序的效果如何
  • SparkSQL之Catelog体系
  • 【操作系统面试题(32道)与面试Linux命令大全】
  • Qt TCP/IP网络通信
  • 全域旅游“一机游”智慧旅游平台解决方案:PPT全文48页,附下载
  • Ubuntu 22.04 (WSL2) 安装 libssl1.1
  • Unity 跑酷游戏全部脚本(完结)
  • 凯美瑞 vs 太空船:Web3 游戏生长的两条路径
  • (一)正点原子I.MX6ULL kernel6.1移植
  • 计算机服务器中了mallox勒索病毒怎么解决,勒索病毒解密,数据恢复
  • CSS3实现动态旋转加载样式
  • 【LeetCode刷题-二分查找】--658.找到K个最接近的元素
  • 新方向!文心一言X具身智能,用LLM大模型驱动智能小车