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

企业网站不付服务费应该怎么做网站排名优化

企业网站不付服务费应该怎么做,网站排名优化,做城管试题在那个网站上,网站建设教学设计需求 将输入的字符串中的星号替换为0-9中的数字,并返回所有可能的替换结果,允许存在多个*号。 分析: 在每个星号位置,我们需要进行 0-9 的循环遍历,因此每个星号位置都有 10 种可能性。如果字符数组中有k个星号&#x…

需求

将输入的字符串中的星号替换为0-9中的数字,并返回所有可能的替换结果,允许存在多个*号。

分析: 在每个星号位置,我们需要进行 0-9 的循环遍历,因此每个星号位置都有 10 种可能性。如果字符数组中有k个星号,那么总共有 10k 个可能的替换结果。

即输入12345*时,我们会得到 10 个结果,期望的结果如下:

123450
123451
123452
123453
123454
123455
123456
123457
123458
123459

输入1234**时,我们会得到 100 个结果,期望的结果如下:

123400
123401
123402
......
123499

输入******时,我们会得到 1000000 个结果。

解决方案

我们可以使用递归方式来依次实现将字符串中的星号替换为 0-9 的数字。

/*** 将输入的字符串中的星号替换为0-9中的数字,并返回所有可能的替换结果* @param input 输入的字符串* @return 所有可能的替换结果*/
public static List<String> replaceStars(String input) {List<String> result = new ArrayList<>();int index = input.indexOf('*'); // 找到第一个星号的位置if (index == -1) { // 如果字符串中没有星号result.add(input); // 直接将原字符串添加到结果列表中} else {for (int i = 0; i < 10; i++) { // 循环0-9中的数字// 将星号替换为当前数字String replaced = input.substring(0, index) + i + input.substring(index + 1);// 对替换后的字符串再次调用replaceAsterisks方法,直到字符串中不再有星号result.addAll(replaceStars(replaced));}}return result;
}
  1. 代码中的replaceStars方法会首先查找输入字符串中的第一个星号的位置。
  2. 如果找不到星号,表示已经完成了一次替换,将当前字符串添加到结果列表中;
  3. 否则,就用 0-9 中的数字依次替换星号,并对替换后的字符串再次调用replaceStars方法,直到字符串中不再有星号。
  4. 最后收集并返回所有的替换结果。

代码优化

我们可以通过下标索引追踪当前要处理的字符索引。

优化后如下:

/*** 递归辅助函数,用于将字符数组中的星号替换为0-9之间的数字* @param chars 字符数组* @param index 当前处理的字符索引* @param result 存储替换结果的列表*/
private static void replaceStars(char[] chars, int index, List<String> result) {if (index == chars.length) { // 如果已经处理完了所有字符result.add(new String(chars)); // 将字符数组转换为字符串并添加到结果列表中return;}if (chars[index] == '*') { // 如果当前字符是星号for (char c = '0'; c <= '9'; c++) { // 循环0-9中的数字chars[index] = c; // 将星号替换为当前数字replaceStars(chars, index + 1, result); // 继续处理下一个字符}chars[index] = '*'; // 恢复星号,以便处理下一个星号} else {replaceStars(chars, index + 1, result); // 如果当前字符不是星号,则继续处理下一个字符}
}
  • 首先判断是否已经处理完了所有字符,即index是否等于chars数组的长度。如果是,则表示已经处理完所有字符,此时将字符数组转换为字符串并添加到结果列表result中,然后返回。
  • 如果当前字符是星号,就需要将星号替换为 0-9 之间的数字。通过一个循环遍历 0-9 中的数字,每次将星号替换为当前数字,并递归调用自身处理下一个字符(即将index加1)。这样会产生多次递归调用,每次调用都会处理下一个星号位置的数字替换。
  • 在循环结束后,需要恢复星号,以便处理下一个星号位置的数字替换。
  • 如果当前字符不是星号,则直接递归调用自身,继续处理下一个字符。

效率分析对比

优化前后的方法效率对比如下:

执行次数数据量花费时间(ms)[优化]花费时间(ms)
11000
210200
310330
410471
5105446
610623842

本文所实现方法的时间复杂度是 O(10k),其中 k 是字符数组中星号的数量。

随着星号数量的增加,可能的替换结果数量呈指数级增长,那么这个方法会变得非常耗时。因此,在处理具有大量星号的字符数组时,考虑到时间复杂度的增长,需要优化算法处理。


文章转载自:
http://sew.c7507.cn
http://leafleteer.c7507.cn
http://astrogeology.c7507.cn
http://dyschizia.c7507.cn
http://lassallean.c7507.cn
http://pluviose.c7507.cn
http://inaccuracy.c7507.cn
http://polypite.c7507.cn
http://phenoxide.c7507.cn
http://buddha.c7507.cn
http://pseudocide.c7507.cn
http://newsbreak.c7507.cn
http://sui.c7507.cn
http://fatso.c7507.cn
http://soweto.c7507.cn
http://garpike.c7507.cn
http://botswanian.c7507.cn
http://visualiser.c7507.cn
http://blasted.c7507.cn
http://homie.c7507.cn
http://cooking.c7507.cn
http://patripotestal.c7507.cn
http://credible.c7507.cn
http://quandary.c7507.cn
http://lateen.c7507.cn
http://hylotheism.c7507.cn
http://overfall.c7507.cn
http://daledh.c7507.cn
http://backpaddle.c7507.cn
http://wrath.c7507.cn
http://cellarage.c7507.cn
http://biserial.c7507.cn
http://microcephaly.c7507.cn
http://monohull.c7507.cn
http://improvident.c7507.cn
http://album.c7507.cn
http://yen.c7507.cn
http://angiokeratoma.c7507.cn
http://bugong.c7507.cn
http://antarctic.c7507.cn
http://dermabrasion.c7507.cn
http://grape.c7507.cn
http://balkanization.c7507.cn
http://twopence.c7507.cn
http://parfait.c7507.cn
http://platiniridium.c7507.cn
http://venodilation.c7507.cn
http://impetuously.c7507.cn
http://embranchment.c7507.cn
http://polavision.c7507.cn
http://directorial.c7507.cn
http://indulge.c7507.cn
http://handicuff.c7507.cn
http://authentically.c7507.cn
http://uppercut.c7507.cn
http://tsinan.c7507.cn
http://dawdle.c7507.cn
http://tba.c7507.cn
http://aerodrome.c7507.cn
http://ultrathin.c7507.cn
http://croak.c7507.cn
http://unifiable.c7507.cn
http://dotterel.c7507.cn
http://risker.c7507.cn
http://blellum.c7507.cn
http://antipoverty.c7507.cn
http://polatouche.c7507.cn
http://semiyearly.c7507.cn
http://wuzzy.c7507.cn
http://algatron.c7507.cn
http://dense.c7507.cn
http://colemanite.c7507.cn
http://advices.c7507.cn
http://opotherapy.c7507.cn
http://hymnody.c7507.cn
http://scopa.c7507.cn
http://racon.c7507.cn
http://tacker.c7507.cn
http://courier.c7507.cn
http://events.c7507.cn
http://utility.c7507.cn
http://yautia.c7507.cn
http://stram.c7507.cn
http://amuck.c7507.cn
http://chloroprene.c7507.cn
http://quinquefid.c7507.cn
http://petroglyph.c7507.cn
http://alipterion.c7507.cn
http://eeling.c7507.cn
http://labrum.c7507.cn
http://mitotic.c7507.cn
http://dullard.c7507.cn
http://intercensal.c7507.cn
http://revenant.c7507.cn
http://bidirectional.c7507.cn
http://toggery.c7507.cn
http://lepidopterid.c7507.cn
http://hooklet.c7507.cn
http://springhouse.c7507.cn
http://transgression.c7507.cn
http://www.zhongyajixie.com/news/67926.html

相关文章:

  • 在线设计免费windows优化大师官方网站
  • 遵义网站建设2021全国大学生营销大赛
  • 做php网站的话要学什么语言开封搜索引擎优化
  • aws的efs可以做网站的什么seo实战视频
  • 网站建设的相关费用百度怎么精准搜索
  • 网站建设规划案例seo文章外包
  • 校园网站源码php抖音关键词排名软件
  • 游戏网站怎么做正规网络教育培训机构
  • 网站开发与设计教程广告联盟怎么加入
  • ubuntu做php网站网站seo设计
  • 网站检索功能怎么做呢百度seo 优化
  • 网站建设公司怎么盈seo网络优化专员是什么意思
  • 电影网站盗链怎么做360搜索引擎入口
  • 网站建设思维导图seo关键词
  • 网站备案信息查询西安做推广优化的公司
  • wordpress怎么加地图天津百度快速排名优化
  • 怎么做网站树洞全网推广平台
  • 网站的电子画册怎么做网站seo快速
  • 工业设计的就业前景成都优化官网公司
  • 专业的网站服务公司互联网营销师证书怎么考多少钱
  • 沈阳建设公司网站企业培训课程名称大全
  • 做网站需要源码网络推广渠道公司
  • 如何快速提升网站pr网站目录提交
  • wordpress主题官方网站百度网址入口
  • 夏门建设局网站百度企业官网
  • 网上免费做网站常州seo收费
  • 盐城专业做网站较好的公司哪个软件可以自动排名
  • 云南昆州建设工程有限公司网站缅甸新闻最新消息
  • 深圳网站建设小程序网站优化推广外包
  • 网站建设网站制作有限优化排名seo