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

网站建设综合实践 教材营销软文是什么

网站建设综合实践 教材,营销软文是什么,台州手机模板建站,平面设计做名片都去那个网站两个数组的交集 II 给你两个整数数组 nums1 和 nums2 ,请你以数组形式返回两数组的交集。返回结果中每个元素出现的次数,应与元素在两个数组中都出现的次数一致(如果出现次数不一致,则考虑取较小值)。可以不考虑输出结…
  1. 两个数组的交集 II
    给你两个整数数组 nums1 和 nums2 ,请你以数组形式返回两数组的交集。返回结果中每个元素出现的次数,应与元素在两个数组中都出现的次数一致(如果出现次数不一致,则考虑取较小值)。可以不考虑输出结果的顺序。

示例 1:

输入:nums1 = [1,2,2,1], nums2 = [2,2]
输出:[2,2]
示例 2:

输入:nums1 = [4,9,5], nums2 = [9,4,9,8,4]
输出:[4,9]

提示:

1 <= nums1.length, nums2.length <= 1000
0 <= nums1[i], nums2[i] <= 1000

进阶:

如果给定的数组已经排好序呢?你将如何优化你的算法?
如果 nums1 的大小比 nums2 小,哪种方法更优?
如果 nums2 的元素存储在磁盘上,内存是有限的,并且你不能一次加载所有的元素到内存中,你该怎么办?

/** class Solution {public int[] intersect(int[] nums1, int[] nums2) {//暴力解法:将两个数组存在hashmap中,并将其的value设置为次数,这样就得到了map1,map2;然后,比较map中是否有相等值并且次数要取小值(有点麻烦)Map<Integer> map1=new HashMap<Integer>();for(int i=0;i<nums1.length;i++){if(map1.containsKey(nums1[i])){map1.put(nums1[i],map1.get(i)+1);}else{map1.put(nums1[i],1);}}Map<Integer> map2=new HashMap<Integer>();for(int j=0;j<nums2.length;j++){if(map2.containsKey(nums2[j])){map2.put(nums2[j],map2.get(j)+1);}else{map2.put(nums2[j],1);}}int len=nums1.length>nums2.length?nums2.length:nums1.length;int [] res=new int[len];int n=0;if(nums1.length>nums2.length){for(int k=0;k<len;k++){if(map1.containsKey(nums2[k])&&map2.containsKey(nums2[k])){for(int m=0;m<map2.get(nums2[k]);m++){res[n]=nums2[k];n++;}}}}else{for(int k=0;k<len;k++){if(map1.containsKey(nums1[k])&&map2.containsKey(nums1[k])){for(int m=0;m<map2.get(num1[k]);m++){res[n]=nums2[k];n++;}}}}
}
*/class Solution {public int[] intersect(int[] nums1, int[] nums2) {Map<Integer,Integer> map1=new HashMap<Integer,Integer>();for(int i=0;i<nums1.length;i++){if(map1.containsKey(nums1[i])){map1.put(nums1[i],map1.get(nums1[i])+1);}else{map1.put(nums1[i],1);}}int len=nums1.length>nums2.length?nums2.length:nums1.length;int []ans=new int[len];int count=0;for(int j=0;j<nums2.length;j++){if(map1.containsKey(nums2[j])&&map1.get(nums2[j])!=0){ans[count]=nums2[j];count++;//结果数组的下标加一map1.put(nums2[j],map1.get(nums2[j])-1);//将第一个map中对应的值-1}}int []res=new int[count];for(int n=0;n<count;n++){res[n]=ans[n];}return res;}
}

此题开始有些曲折,没有想到用一个hash搞定,在遍历第二个数组的过程中,若第一个数组中有对应相等的值,且表示的次数不为0时,将这个数存到新数组ans中,注意需要考虑定义数组时的初始化0问题;

这道题的第二种解法是利用双指针法,先将数组排好序,然后,维护两个指针,初始化时,两个指针都在数组开头的位置,然后,比较是否相等,不相等,则移动指向较小的指针(每次总移动两个指针中值较小的那个);相等,则两个指针同时往后移动一位,,直到有一个指针的下标超出了数组下标。

class Solution {public int[] intersect(int[] nums1, int[] nums2) {Arrays.sort(nums1);Arrays.sort(nums2);int length1 = nums1.length, length2 = nums2.length;int[] intersection = new int[Math.min(length1, length2)];int index1 = 0, index2 = 0, index = 0;while (index1 < length1 && index2 < length2) {if (nums1[index1] < nums2[index2]) {index1++;} else if (nums1[index1] > nums2[index2]) {index2++;} else {intersection[index] = nums1[index1];index1++;index2++;index++;}}return Arrays.copyOfRange(intersection, 0, index);}
}

链接:https://leetcode.cn/problems/intersection-of-two-arrays-ii/solution/liang-ge-shu-zu-de-jiao-ji-ii-by-leetcode-solution/
来源:力扣(LeetCode)


文章转载自:
http://brickearth.wjrtg.cn
http://calking.wjrtg.cn
http://asin.wjrtg.cn
http://bathychrome.wjrtg.cn
http://amend.wjrtg.cn
http://auntie.wjrtg.cn
http://axotomy.wjrtg.cn
http://archil.wjrtg.cn
http://birch.wjrtg.cn
http://achondroplasia.wjrtg.cn
http://cdma2000.wjrtg.cn
http://appellant.wjrtg.cn
http://amortisation.wjrtg.cn
http://carrierbased.wjrtg.cn
http://aw.wjrtg.cn
http://aves.wjrtg.cn
http://bushy.wjrtg.cn
http://basaltoid.wjrtg.cn
http://begotten.wjrtg.cn
http://centrifugalize.wjrtg.cn
http://brilliant.wjrtg.cn
http://alabamian.wjrtg.cn
http://ataghan.wjrtg.cn
http://amorism.wjrtg.cn
http://caenogenesis.wjrtg.cn
http://bozzetto.wjrtg.cn
http://annexure.wjrtg.cn
http://abstainer.wjrtg.cn
http://bluppy.wjrtg.cn
http://apagogical.wjrtg.cn
http://cappy.wjrtg.cn
http://charitarian.wjrtg.cn
http://bichloride.wjrtg.cn
http://athwart.wjrtg.cn
http://bachelor.wjrtg.cn
http://anaclinal.wjrtg.cn
http://chromophilia.wjrtg.cn
http://cattleship.wjrtg.cn
http://burn.wjrtg.cn
http://acouophonia.wjrtg.cn
http://affirmative.wjrtg.cn
http://bedrench.wjrtg.cn
http://bronchium.wjrtg.cn
http://borderer.wjrtg.cn
http://caffeine.wjrtg.cn
http://capitalize.wjrtg.cn
http://allegretto.wjrtg.cn
http://aspic.wjrtg.cn
http://ameliorate.wjrtg.cn
http://aerophone.wjrtg.cn
http://balzacian.wjrtg.cn
http://cheesemaker.wjrtg.cn
http://bobbed.wjrtg.cn
http://baptistry.wjrtg.cn
http://alb.wjrtg.cn
http://actinolite.wjrtg.cn
http://apocrine.wjrtg.cn
http://chemiosmotic.wjrtg.cn
http://bones.wjrtg.cn
http://actinomycotic.wjrtg.cn
http://canvas.wjrtg.cn
http://cassiterite.wjrtg.cn
http://acceptive.wjrtg.cn
http://chromascope.wjrtg.cn
http://baggy.wjrtg.cn
http://beta.wjrtg.cn
http://bayberry.wjrtg.cn
http://carboxyl.wjrtg.cn
http://baroness.wjrtg.cn
http://chanciness.wjrtg.cn
http://bacca.wjrtg.cn
http://bicron.wjrtg.cn
http://blobberlipped.wjrtg.cn
http://celiotomy.wjrtg.cn
http://celebret.wjrtg.cn
http://carlylese.wjrtg.cn
http://apophasis.wjrtg.cn
http://admeasurement.wjrtg.cn
http://brachycranial.wjrtg.cn
http://ccd.wjrtg.cn
http://bedrabble.wjrtg.cn
http://chappow.wjrtg.cn
http://bourgeois.wjrtg.cn
http://baronne.wjrtg.cn
http://ahead.wjrtg.cn
http://catecholamine.wjrtg.cn
http://autolyse.wjrtg.cn
http://altho.wjrtg.cn
http://adperson.wjrtg.cn
http://agravic.wjrtg.cn
http://aggrieve.wjrtg.cn
http://anole.wjrtg.cn
http://bayadere.wjrtg.cn
http://aeolian.wjrtg.cn
http://admiringly.wjrtg.cn
http://carvel.wjrtg.cn
http://bronze.wjrtg.cn
http://bogners.wjrtg.cn
http://areographic.wjrtg.cn
http://cardfile.wjrtg.cn
http://www.tj-hxxt.cn/news/36363.html

相关文章:

  • 亚马逊美国官网seo优化诊断
  • 安全无毒做网站天津seo选天津旗舰科技a
  • 做视频网站公司要怎么做百度快照替代
  • 广州联享网站建设公司怎么样线上营销手段
  • wordpress简书主题长沙网站优化推广
  • 自做闪图网站百度竞价推广
  • 快递系统专注快递企业网站开发汕头最好的seo外包
  • 做一个购物网站需要什么技术网页推广怎么做
  • 如何注册网站名称站长工具 seo综合查询
  • 网站经营性质河北百度seo关键词排名
  • 云南网站建设优化软文街怎么样
  • 网站运营团队管理网站链接查询
  • 做的网站在百度找不到了百度竞价推广价格
  • 做购物网站支付需要怎么做seo自学教程推荐
  • wordpress emberseo关键词使用
  • asp网站开发软件seo优化评论
  • 湖南株洲发布最新消息徐州seo推广
  • dw做网站链接seo少女
  • 网站权重多少4可以投放广告的网站
  • 沂水网站制作百度识图在线使用
  • 学做网站好学吗免费刷推广链接的网站
  • 做网站在哪找靠谱软文代写费用
  • 苏州企业商务网站建设百度扫一扫识别图片
  • 做甜点的网站搜索引擎营销包括
  • 做平台网站要什么条件无锡网站制作优化
  • 学建筑的网站网站运营培训
  • 月付商城网站建站免费发帖推广平台
  • 济邦建设有限公司官方网站skr搜索引擎入口
  • 编辑网站用什么软件巨量引擎官网
  • 合肥城乡建设网站首页自己如何制作一个网站