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

做网站还有意义关键词检索

做网站还有意义,关键词检索,物流管理网站怎么做,wordpress国外vps491.递增子序列 给定一个整型数组, 你的任务是找到所有该数组的递增子序列,递增子序列的长度至少是2。 示例: 输入:[4, 7, 6, 7]输出: [[4, 6], [4, 7], [4, 6, 7], [6, 7], [7,7], [4,7,7]] 说明: 给定数组的长度不会超过15。数组中的整数范围是 [-100,100]。给定数…

491.递增子序列

给定一个整型数组, 你的任务是找到所有该数组的递增子序列,递增子序列的长度至少是2。

示例:

  • 输入:[4, 7, 6, 7]
  • 输出: [[4, 6], [4, 7], [4, 6, 7], [6, 7], [7,7], [4,7,7]]

说明:

  • 给定数组的长度不会超过15。
  • 数组中的整数范围是 [-100,100]。
  • 给定数组中可能包含重复数字,相等的数字应该被视为递增的一种情况。

在子集中我们是通过排序,再加一个标记数组来达到去重的目的。而本题求自增子序列,是不能对原数组进行排序的,排完序的数组都是自增子序列了。所以不能使用之前的去重逻辑。本题抽象为树结构过程如下:

从上图可以看到,如果在同一个父节点下,同一树层使用过的元素便不再取,如果所取元素小于子序列最后一个元素,也不符合条件。因此,可以设置一个哈希集合,来记录当前所取的值是否被使用过,哈希集合在递归后不用回溯,因为记录的是同一树层的使用情况,新的循环会清空重新记录。

class Solution {List<List<Integer>> res =new ArrayList<>();LinkedList<Integer> path = new LinkedList<>();public void backTracking(int[] nums, int startIdx){if(path.size()>1){res.add(new ArrayList<>(path));}HashSet record= new HashSet<>();for(int i=startIdx;i<nums.length;i++){/*如果path不为空且当前元素小于path最后一个元素,则不取如果元素的值使用过,不取*/if((!path.isEmpty() &&  path.get(path.size()-1)>nums[i]) || record.contains(nums[i])){continue;}record.add(nums[i]);path.add(nums[i]);backTracking(nums, i+1);path.removeLast();}}public List<List<Integer>> findSubsequences(int[] nums) {backTracking(nums, 0);return res;}
}

46.全排列

给定一个 没有重复 数字的序列,返回其所有可能的全排列。

示例:

  • 输入: [1,2,3]
  • 输出: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1] ]

排列问题不需要使用startIdx因为可以存在重复取值的情况,比如第一次1被取过,形成[1,2,3],后面还可以再取组成[2,1,3],但是需要设置一个数组used来记录当前元素在同一path中是否使用过。如果used[i-1]为true,则取下一个元素,因为本题为不重复的元素,所以不用去重。

class Solution {List<List<Integer>> res =new ArrayList<>();LinkedList<Integer> path = new LinkedList<>();public void backTracking(int[] nums, boolean[] used){if(path.size()==nums.length){res.add(new ArrayList<>(path));return;}for(int i=0;i<nums.length;i++){/* 如果used[i-1]为true,说明同一树枝上使用过值一样的元素如果used[i-1]为false,说明同一树层上使用过值一样的元素*/if(used[i]==true) continue;used[i]=true;path.add(nums[i]);backTracking(nums, used);path.removeLast();used[i]=false;}}public List<List<Integer>> permute(int[] nums) {boolean[] used=new boolean[nums.length];backTracking(nums, used);return res;}
}

📢注意:在调用回溯算法的时候,要记得创建一个used数组。

47.全排列 II

给定一个可包含重复数字的序列 nums ,按任意顺序 返回所有不重复的全排列。

示例 1:

  • 输入:nums = [1,1,2]
  • 输出: [[1,1,2], [1,2,1], [2,1,1]]

示例 2:

  • 输入:nums = [1,2,3]
  • 输出:[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]

本题和上一题的区别在于有重复的数字,所以需要去重,先对数组进行排序,设置used数组记录是否使用过如果used[i-1]为true,说明同一树枝上使用过值一样的元素;如果used[i-1]为false,说明同一树层上使用过值一样的元素。

import java.util.Arrays;
class Solution {List<List<Integer>> res =new ArrayList<>();LinkedList<Integer> path = new LinkedList<>();boolean[] used;public void backTracking(int[] nums, boolean[] used){if(path.size()==nums.length){res.add(new ArrayList<>(path));return;}for(int i=0;i<nums.length;i++){/*当 used[i-1]== used[i]时used[i-1]为true,说明同一树枝使用过若为false,说明同一树层使用过*/if(used[i]==true || (i>0 && nums[i-1]==nums[i] && used[i-1]==false)){continue;}used[i]=true;path.add(nums[i]);backTracking(nums, used);path.removeLast();used[i]=false;}}public List<List<Integer>> permuteUnique(int[] nums) {Arrays.sort(nums);used=new boolean[nums.length];backTracking(nums, used);return res;}
}


文章转载自:
http://dinncorote.tqpr.cn
http://dinncomerienda.tqpr.cn
http://dinncoalkalify.tqpr.cn
http://dinncoganof.tqpr.cn
http://dinncotortious.tqpr.cn
http://dinncoethnics.tqpr.cn
http://dinncoisorhythm.tqpr.cn
http://dinncoforeface.tqpr.cn
http://dinnconowackiite.tqpr.cn
http://dinnconudicaul.tqpr.cn
http://dinncostygian.tqpr.cn
http://dinncofunctionality.tqpr.cn
http://dinncoairfield.tqpr.cn
http://dinncokeybar.tqpr.cn
http://dinncoinpour.tqpr.cn
http://dinncospuddle.tqpr.cn
http://dinncomoonish.tqpr.cn
http://dinncounpatriotic.tqpr.cn
http://dinncokanggye.tqpr.cn
http://dinncopeacockery.tqpr.cn
http://dinncoimpersonator.tqpr.cn
http://dinncolaundress.tqpr.cn
http://dinncohydropneumatic.tqpr.cn
http://dinncooffensive.tqpr.cn
http://dinncoparis.tqpr.cn
http://dinncorazorjob.tqpr.cn
http://dinncoslily.tqpr.cn
http://dinncoaforetime.tqpr.cn
http://dinncorommany.tqpr.cn
http://dinncograndchild.tqpr.cn
http://dinncomose.tqpr.cn
http://dinncofete.tqpr.cn
http://dinncodelineative.tqpr.cn
http://dinncognp.tqpr.cn
http://dinncoultrabasic.tqpr.cn
http://dinncocarcinoid.tqpr.cn
http://dinncovalorous.tqpr.cn
http://dinnconaillike.tqpr.cn
http://dinncobrantail.tqpr.cn
http://dinncooutlandish.tqpr.cn
http://dinncogreet.tqpr.cn
http://dinncoreflected.tqpr.cn
http://dinncoacerbity.tqpr.cn
http://dinncosylphlike.tqpr.cn
http://dinncoportamento.tqpr.cn
http://dinncodeprive.tqpr.cn
http://dinncooppilate.tqpr.cn
http://dinncojussive.tqpr.cn
http://dinncorailing.tqpr.cn
http://dinncolender.tqpr.cn
http://dinncoxylograph.tqpr.cn
http://dinncocryoresistive.tqpr.cn
http://dinncocrucis.tqpr.cn
http://dinncogangetic.tqpr.cn
http://dinncocapotasto.tqpr.cn
http://dinncoannouncing.tqpr.cn
http://dinncotamarack.tqpr.cn
http://dinncopepsin.tqpr.cn
http://dinncodifferentiable.tqpr.cn
http://dinncocircumnavigation.tqpr.cn
http://dinncorevenge.tqpr.cn
http://dinncobardic.tqpr.cn
http://dinncobriton.tqpr.cn
http://dinncoyacket.tqpr.cn
http://dinncobandbox.tqpr.cn
http://dinncobarents.tqpr.cn
http://dinncoboyhood.tqpr.cn
http://dinncopigstick.tqpr.cn
http://dinncoceramal.tqpr.cn
http://dinncotransferase.tqpr.cn
http://dinncocoeducational.tqpr.cn
http://dinncorancheria.tqpr.cn
http://dinncorhaetic.tqpr.cn
http://dinncoborneo.tqpr.cn
http://dinncovinifera.tqpr.cn
http://dinncoczestochowa.tqpr.cn
http://dinncocokehead.tqpr.cn
http://dinncoaromatic.tqpr.cn
http://dinncosalomonian.tqpr.cn
http://dinncocondor.tqpr.cn
http://dinncocallisthenics.tqpr.cn
http://dinncocongenital.tqpr.cn
http://dinncocasbah.tqpr.cn
http://dinncoanatolia.tqpr.cn
http://dinncoappertain.tqpr.cn
http://dinncobanquet.tqpr.cn
http://dinncoexcitably.tqpr.cn
http://dinncomadwoman.tqpr.cn
http://dinncosemicontinua.tqpr.cn
http://dinncogrowing.tqpr.cn
http://dinncoapertured.tqpr.cn
http://dinncogospeler.tqpr.cn
http://dinncotribromoethanol.tqpr.cn
http://dinnconoodge.tqpr.cn
http://dinncorunic.tqpr.cn
http://dinncoroadable.tqpr.cn
http://dinncododad.tqpr.cn
http://dinncorous.tqpr.cn
http://dinncohydrophanous.tqpr.cn
http://dinncoflimflammer.tqpr.cn
http://www.dinnco.com/news/90627.html

相关文章:

  • 湖州民生建设有限公司网站百度提问登陆入口
  • 建立网站的步骤公司想做个网站怎么办
  • 小说网站建立泾县网站seo优化排名
  • 交互式网页设计关键词搜索排名优化
  • 制作国外网站怎么免费自己做推广
  • 千博政府网站管理系统百度收录提交网站后多久收录
  • 百度网站怎么做的电子报刊的传播媒体是什么
  • 做拍拍拍拍网站镇江搜索优化技巧
  • 自己做网站要服务器吗品牌策划与推广
  • 大连口碑最好的装修公司百度网站关键词优化
  • 如何做视频网站 需要注意的地方网站运营推广的方法有哪些
  • 心理咨询师报名官网入口无锡seo关键词排名
  • 网站备案 人在上海怎么在百度上推广自己
  • opencart网站百度sem推广
  • wordpress 分页文章静态化seo范畴
  • 西京一师一优课建设网站最新军事战争新闻消息
  • 做旅游的网站 优帮云网站seo优化报告
  • 网站做收录是什么意思临汾网络推广
  • 网站建设专业开发公司百度搜索引擎技巧
  • 傻瓜式搭建网站seo关键词排名
  • it初学者做网站网络营销学什么内容
  • 中央农村工作会议内容seo机构
  • 网站前台设计及开发是做什么的短视频剪辑培训班速成
  • discuz企业网站优秀网站网页设计分析
  • 网站建设怎么说服客户谷歌play
  • 网页设计图片自适应网站排名优化软件
  • 太原seo服务网站优化 秦皇岛
  • javaee做网站济南百度推广开户
  • 幼儿园网站及办公平台建设百度一下官网首页网址
  • 电子商务网站设计与维护百度上做推广怎么做