目录
- class Solution {
- public int maximumStrongPairXor(int[] a) {
-
- int n=a.length,max=0;
- for(int i=0;i
- {
- for(int j=i;j
- {
- if(Math.abs(a[i]-a[j])<=Math.min(a[i],a[j]))
- {
- max=Math.max(max,a[i]^a[j]);
- }
- }
- }
- return max;
- }
- }
2、高访问员工 - 哈希表 + 模拟
思路:
名字存其下所有时间(换算成分钟数),然后进行排序
另每个时间+59=限制时间,向该时间后查找,如果出现2个小于限制时间,则将该名字存入答案并跳出遍历下一个名字
- class Solution {
- public List
findHighAccessEmployees(List> a)
{ - Map
> mp=new HashMap<>(); - List
res=new ArrayList<>(); - for(int i=0;i
- {
- String name=a.get(i).get(0);
- String time=a.get(i).get(1);
- List
t=mp.getOrDefault(name,new ArrayList<>()); - t.add(trans(time));
- mp.put(name,t);
- }
- for(Map.Entry
> x:mp.entrySet()) - {
- List
t=x.getValue(); - String name=x.getKey();
- Collections.sort(t);
- System.out.println(name+" "+t);
- boolean f=false;
- for(int i=0;i
2;i++) - {
- if(f) break;
- int limt=t.get(i)+59,cnt=1;
- for(int j=i+1;j
- {
- if(t.get(j)<=limt) cnt++;
- if(cnt==3)
- {
- f=true;
- res.add(name);
- break;
- }
- }
- }
- }
- return res;
- }
- public int trans(String s)
- {
- int res=Integer.parseInt(s.substring(0,2))*60+Integer.parseInt(s.substring(2));
- return res;
- }
-
- }
3、最大化数组末位元素的最少操作次数 - 思维 + 贪心
思路:
只有两种情况:
- 交换最后一位数
- 不交换最后一位数
对这两种情况,再遍历【0~n-2】序号的数i
- 如果若 nums1[i]>nums1[n−1]或 nums2[i]>nums2[n−1],则交换 nums1[i]和 nums2[i]
- 若交换后仍有 nums1[i]>nums1[n−1] 或 nums2[i]>nums2[n−1],则当前情况无解
- class Solution {
- public int minOperations(int[] nums1, int[] nums2) {
- int n=nums1.length;
- return Math.min(f(nums1[n-1],nums2[n-1],nums1,nums2),1+f(nums2[n-1],nums1[n-1],nums1,nums2));
- }
-
- public int f(int last1,int last2,int[] a,int[] b)
- {
- int res=0;
- for(int i=0;i
1;i++) - {
- if(a[i]>last1||b[i]>last2)
- {
- if(b[i]>last1||a[i]>last2) //如果交换后 仍不满足条件,则后面无论怎么换都存在数组内元素大于末尾元素,返回-1
- return -1;
- res++;
- }
- }
- return res;
- }
- }
-
相关阅读:
Cefsharp开发中遇到的问题
[附源码]Python计算机毕业设计SSM篮球资讯网站(程序+LW)
ThingsBoard 实现设备认领
Java on Azure Tooling 8月更新|以应用程序为中心的视图支持及 Azure 应用服务部署状态改进
MATLAB--pie函数绘制复杂分类饼图(2)--附案例代码
LLVM IR 构建 分析 转换 优化 IRBuilder Pass AI编译器后端代码生成
恒峰智慧科技-太阳能语音杆:一杆多用,节能环保新选择!
SpringMvc+Spring+MyBatis+Maven+Ajax+Json注解开发 利用Maven的依赖导入不使用架包模式 (实操十)
【PostgreSQL】事务、并发、锁
Spark--经典SQL50题
-
原文地址:https://blog.csdn.net/weixin_61639349/article/details/134429780