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

广州越秀区酒店好口碑关键词优化

广州越秀区酒店,好口碑关键词优化,成都哪家公司做网站最好,移动端网站宽度做多大该算法是临时想出来的,Java代码的实现在时间上不占优,之后有时间要优化一下,目前就是给大家提供一下思路。 解题思路:田忌赛马的思想 贪心法。 Step1. 对两个数组进行排序。 Step2. 同时遍历排序后的nums2和nums1,将…

该算法是临时想出来的,Java代码的实现在时间上不占优,之后有时间要优化一下,目前就是给大家提供一下思路。

解题思路:田忌赛马的思想 + 贪心法。

Step1. 对两个数组进行排序。

Step2. 同时遍历排序后的nums2和nums1,将num1中刚好超过nums2当前值的值放到对应的位置,而不超过nums2当前值的值放到最后面去,因为反正这些值超不过nums2,不如把num1中较小的值用来对应nums2中较大的值。

Java代码

import java.util.Arrays;
import java.util.Comparator;
import java.util.stream.IntStream;public class AdvantageCount {public static void main(String[] args) {Solution sol = new Solution();System.out.println(Arrays.toString(sol.advantageCount(new int[]{2,7,11,15}, new int[]{1,10,4,11})));System.out.println(Arrays.toString(sol.advantageCount(new int[]{12,24,8,32}, new int[]{13,25,32,11})));}
}class ArrayIndexComparator implements Comparator<Integer> {private final Integer[] A;public ArrayIndexComparator(Integer[] arr) {this.A = arr;}public int compare(Integer o1, Integer o2) {return A[o1].compareTo(A[o2]);}
}class Solution {public int[] advantageCount(int[] nums1, int[] nums2) {int n = nums1.length;// int[] -> Integer[]Integer[] nums2Integers =  Arrays.stream(nums2).boxed().toArray(Integer[]::new);// 排序后返回原索引Integer[] nums2Indexs = new Integer[n];IntStream.range(0, n).forEach(val -> nums2Indexs[val] = val);Arrays.sort(nums2Indexs, new ArrayIndexComparator(nums2Integers));int[] new_nums1 = new int[n];Arrays.sort(nums1);int j = 0;int k = n - 1;for (int i = 0; i < n; i++) {while(j < n && nums1[j] <= nums2[nums2Indexs[i]]){new_nums1[nums2Indexs[k]] = nums1[j];k--;j++;}if(j < n){new_nums1[nums2Indexs[i]] = nums1[j];j++;}}return new_nums1;}
}

完整题目

870. 优势洗牌

给定两个长度相等的数组 nums1 和 nums2nums1 相对于 nums2 的优势可以用满足 nums1[i] > nums2[i] 的索引 i 的数目来描述。

返回 nums1 的任意排列,使其相对于 nums2 的优势最大化。

示例 1:

输入:nums1 = [2,7,11,15], nums2 = [1,10,4,11]
输出:[2,11,7,15]

示例 2:

输入:nums1 = [12,24,8,32], nums2 = [13,25,32,11]
输出:[24,32,8,12]

提示:

  • 1 <= nums1.length <= 10^5
  • nums2.length == nums1.length
  • 0 <= nums1[i], nums2[i] <= 10^9

 

http://www.dt0577.cn/news/42329.html

相关文章:

  • 网站建设最新活动西地那非片的功效与作用
  • 静态网站开发 内容搜索引擎优化什么意思
  • 如何制作家具网站拓客app下载
  • 做公司网站需要提供的资料万能bt搜索引擎网站
  • 滁州网站建设bpbqq免费域名申请个人网站
  • 页面设计班重庆seo论坛
  • 凡科建设网站怎样收录百度深圳推广网络
  • 惠州注册公司代办公司网站推广怎么优化
  • 网站建设 电子政务企业网站制作流程
  • 南通做微网站美工培训
  • 帝国做的电影网站南京seo推广
  • 卖汽车的网站怎么做百度客服平台
  • 物流相关网站聚名网域名
  • 怎么做淘课网站seo详细教程
  • 房地产微网站模板个人seo怎么赚钱
  • 红酒 专业 网站建设老铁外链工具
  • 做下一个盗版小说网站百度官网下载安装到桌面上
  • 东森推广官网seo关键词库
  • 杭州外贸网站建设公司价格风云榜
  • 怎么做足球直播网站2345网址导航手机版
  • 旅游网站建设普通论文淘宝引流推广怎么做
  • 做网站公司 郑州营销策划推广公司
  • 网站怎么建立真正免费的网站建站平台运营
  • 南宁中小企业网站制作推广活动策划方案范文
  • 儿童网站设计南京网站建设
  • 泉州做网站qzxiaolv网站排行榜查询
  • 简单网站搭建百度公司的业务范围
  • 电子商务论文8000字系统优化大师官方下载
  • 基于html5的网站设计毕业论文seo推广怎么学
  • 北京 网站建设|小程序|软件开发|app开发公司网站推广的方式有哪些?