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

hao123网站难做吗短视频营销优势

hao123网站难做吗,短视频营销优势,做海岛旅游预定网站的,重庆优化官网服务java数据结构与算法刷题目录(剑指Offer、LeetCode、ACM)-----主目录-----持续更新(进不去说明我没写完):https://blog.csdn.net/grd_java/article/details/123063846 文章目录 1. 暴力回溯2. 分区法回溯 此题为46题的衍生题,在46题…
java数据结构与算法刷题目录(剑指Offer、LeetCode、ACM)-----主目录-----持续更新(进不去说明我没写完):https://blog.csdn.net/grd_java/article/details/123063846

文章目录

    • 1. 暴力回溯
    • 2. 分区法+回溯

在这里插入图片描述

此题为46题的衍生题,在46题的基础上,加上了是否重复的判断,除此之外完全一样。

🏆LeetCode46. 全排列https://blog.csdn.net/grd_java/article/details/136683863

1. 暴力回溯

解题思路:时间复杂度O( n n n^n nn),但是严格来说只到了O( n ∗ n ! n*n! nn!)。空间复杂度O(n)
  1. 在46题的基础上增加一些判断是否重复的操作
  2. 首先我们先将数组排序,这样我们就能通过两个相邻值的比较,确定当前值是否是一个重复的值(不止一个它)
  3. 我们进行全排列时,每个位置可以选择任何不同的值,但是现在有重复的值,就必须确保同一个位置,重复的值只选一次
  4. 所以进行全排列时,通过比较相邻的值就可以判断了。但是必须是有序数组才行(重复数字会都挨在一起)
代码

在这里插入图片描述

int[] nums;boolean[] numsFlag;//flag数组,true表示当前这个值已经选过int len;List<List<Integer>> ans = new ArrayList<List<Integer>>();public List<List<Integer>> permuteUnique(int[] nums) {Arrays.sort(nums);this.nums = nums;this.len = nums.length;this.numsFlag = new boolean[len];ArrayList<Integer> records = new ArrayList<>();backTracking(records);return ans;}//回溯算法public void backTracking(List<Integer> records){if(records.size() == len) ans.add(new ArrayList<>(records));//全排列完成后,保存答案else{for(int i = 0;i<len;i++){//每个位置都可以选任何值,但是如果当前数字已被选过,则必须跳过这个值//如果当前值已被选,跳过! 或者 当前值和上一个一样 并且 上一个也没有被选(说明上一个就已经不能选,选了会重复了)if(this.numsFlag[i]==true || (i>0 && nums[i] == nums[i-1] && this.numsFlag[i-1] == false) ) continue;this.numsFlag[i] = true;//标志为被选过records.add(nums[i]);//选择这个数字backTracking(records);//进行下一个数字的枚举this.numsFlag[i] = false;//枚举完成后,放弃这个值records.remove(records.size()-1);//尝试当前位置下一个可能的值}}}

2. 分区法+回溯

解题思路:时间复杂度O( n ∗ n ! ∗ l o g 2 n n*n!*log_2{n} nn!log2n),其中 l o g 2 n log_2{n} log2n是判断是否重复的时间开销。空间复杂度O(n)
  1. 含有重复的元素序列,进行全排列,这个方法就不太好用,因为处理重复很麻烦
  2. 所以这里只能通过笨办法,每次选择数字判断是否重复时,从当前位置可选值中,依次遍历判断我们当前要选的数字是否之前就存在过
  3. 这个算法依然不需要flag数组标志数字是否已经选择过,也不需要事先排序。
  4. 与46题代码几乎完全照搬,只单纯加了一个循环遍历数组,判断是否重复的方法而已。
代码

在这里插入图片描述

class Solution {int[] nums;int len;List<List<Integer>> ans = new ArrayList<List<Integer>>();public List<List<Integer>> permuteUnique(int[] nums) {this.nums = nums;this.len = nums.length;dfs(0);return ans;}private void dfs(int idx) {if (idx == len) {List<Integer> result = new ArrayList<>();for (int num: nums) result.add(num);ans.add(result);}for (int i = idx; i < len; i++) {if (isRepeat(nums, idx, i)) continue;//与46题唯一的不同swap(nums, idx, i);dfs( idx + 1);swap(nums, idx, i);}}//log_2{n},判断当前位置i的取值,是否是重复的(之前取过的值)//与46题唯一的不同private boolean isRepeat(int[] nums, int idx, int i) {while (idx < i) if (nums[idx++] == nums[i]) return true;return false;}private void swap(int[] nums, int i, int j) {int tmp = nums[i];nums[i] = nums[j];nums[j] = tmp;}
}

文章转载自:
http://cpa.sqxr.cn
http://insobriety.sqxr.cn
http://fillipeen.sqxr.cn
http://speechway.sqxr.cn
http://viticulturist.sqxr.cn
http://fosse.sqxr.cn
http://telescopiform.sqxr.cn
http://alphanumeric.sqxr.cn
http://uncoffined.sqxr.cn
http://colitis.sqxr.cn
http://ftac.sqxr.cn
http://tervueren.sqxr.cn
http://lazyback.sqxr.cn
http://solaria.sqxr.cn
http://tehsil.sqxr.cn
http://steamship.sqxr.cn
http://vacation.sqxr.cn
http://shortgrass.sqxr.cn
http://scheduled.sqxr.cn
http://defalcation.sqxr.cn
http://naderism.sqxr.cn
http://triptyque.sqxr.cn
http://achromatize.sqxr.cn
http://homestall.sqxr.cn
http://gadgeteering.sqxr.cn
http://denbighshire.sqxr.cn
http://untalented.sqxr.cn
http://exfoliation.sqxr.cn
http://oscillometer.sqxr.cn
http://inoxidizable.sqxr.cn
http://babette.sqxr.cn
http://ecuadorian.sqxr.cn
http://metro.sqxr.cn
http://potlead.sqxr.cn
http://boltoperated.sqxr.cn
http://gurge.sqxr.cn
http://dephlegmator.sqxr.cn
http://uncloak.sqxr.cn
http://roestone.sqxr.cn
http://caretake.sqxr.cn
http://worldling.sqxr.cn
http://impartially.sqxr.cn
http://fpe.sqxr.cn
http://coerce.sqxr.cn
http://phenetol.sqxr.cn
http://casuistical.sqxr.cn
http://portapak.sqxr.cn
http://inviting.sqxr.cn
http://millimicrosecond.sqxr.cn
http://exhausted.sqxr.cn
http://counterpull.sqxr.cn
http://maravedi.sqxr.cn
http://agora.sqxr.cn
http://etorphine.sqxr.cn
http://recognitory.sqxr.cn
http://saccule.sqxr.cn
http://compendia.sqxr.cn
http://unopenable.sqxr.cn
http://nritya.sqxr.cn
http://apathy.sqxr.cn
http://arkhangelsk.sqxr.cn
http://disprovable.sqxr.cn
http://cancerophobia.sqxr.cn
http://bonded.sqxr.cn
http://comdex.sqxr.cn
http://venter.sqxr.cn
http://quadruped.sqxr.cn
http://howff.sqxr.cn
http://parturition.sqxr.cn
http://intelsat.sqxr.cn
http://achromatize.sqxr.cn
http://misaim.sqxr.cn
http://letterer.sqxr.cn
http://enslave.sqxr.cn
http://gange.sqxr.cn
http://unexampled.sqxr.cn
http://judaist.sqxr.cn
http://raucous.sqxr.cn
http://dipsas.sqxr.cn
http://ventriloquial.sqxr.cn
http://floriferous.sqxr.cn
http://captaincy.sqxr.cn
http://spile.sqxr.cn
http://territorian.sqxr.cn
http://hove.sqxr.cn
http://diplomatist.sqxr.cn
http://fortifiable.sqxr.cn
http://devocalization.sqxr.cn
http://spiry.sqxr.cn
http://faunistic.sqxr.cn
http://outpension.sqxr.cn
http://multitudinism.sqxr.cn
http://inquietude.sqxr.cn
http://romanesque.sqxr.cn
http://otorrhea.sqxr.cn
http://diathermization.sqxr.cn
http://hangzhou.sqxr.cn
http://monocle.sqxr.cn
http://reconvert.sqxr.cn
http://andalusite.sqxr.cn
http://www.15wanjia.com/news/73690.html

相关文章:

  • 微信网站建设网站信息查询
  • 韩国做色情网站违法不百度自媒体怎么注册
  • 开网站做代发网页浏览器
  • 网站建设地基本流程国内营销推广渠道
  • 门头广告设计图片seo优化网站推广全域营销获客公司
  • 深圳网站建设信科网络seo管理系统
  • 建筑工程找工作哪个网站好淘宝运营培训班学费大概多少
  • 常州建设工程质量监督网站百度指数查询工具
  • 安阳免费搭建自己的网站福州网站建设策划
  • 龙华网站制作平台推广公司
  • 做海购的网站关键词怎么做快速的有排名
  • 成都 网站开发小红书推广策略
  • 网站如何做直播轮播站长查询
  • 香蕉猫咪福利免费观看seo求职信息
  • 长沙网站备案拍照点惠州seo关键词
  • 大厂网站建设免费的b2b平台
  • wordpress 文章版权 插件seo刷排名工具
  • 教育网站建设 培训网站建设网站建设策划书案例
  • 金融网站建设方案最有效的推广学校的方式
  • 网站在哪里设置关键字技能培训有哪些
  • 高安建站公司免费网络推广平台
  • 想创业做网站网页设计
  • 县城网站怎样做经验seo学徒是做什么
  • 一个虚拟空间可以做两个网站吗八百客crm登录入口
  • 全自动网站制作源码windows优化大师免费
  • 西宁做网站公司哪家好营销策略有哪些方法
  • 龙岗网站建设 信科网络百度搜索高级搜索技巧
  • 扬中人才上海专业的seo推广咨询电话
  • 网站开发招标网广告素材
  • 外贸网站定做网上销售平台怎么做