目录
- 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;
- }
- }
-
相关阅读:
vs2019_qt6.2.4_dcmtk3.6.7_vtk9.2.2_itk5.3_opencv4.6.0编译记录
学习笔记——sklearn数据预处理和特征工程(过滤法、嵌入法、包装法)
精彩,Excel成为编程语言,国产重量级选手再也坐不住了
不同层设置不同学习率
docker
未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序
Docker—容器数据卷
linux错误处理函数
现代计算方法或可使潜艇狼群战术再现
Vue模板语法(下)
-
原文地址:https://blog.csdn.net/weixin_61639349/article/details/134429780