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

做外包网站搭建何鹏seo

做外包网站搭建,何鹏seo,青岛网站建设seo优化制作设计,网站开发与设计英文文献题目链接 去除重复字母 题目描述 注意点 s 由小写英文字母组成1 < s.length < 10^4需保证 返回结果的字典序最小&#xff08;要求不能打乱其他字符的相对位置&#xff09; 解答思路 本题与移掉 K 位数字类似&#xff0c;需要注意的是&#xff0c;并不是每个字母都能…

题目链接

去除重复字母

题目描述

注意点

  • s 由小写英文字母组成
  • 1 <= s.length <= 10^4
  • 需保证 返回结果的字典序最小(要求不能打乱其他字符的相对位置)

解答思路

  • 本题与移掉 K 位数字类似,需要注意的是,并不是每个字母都能被移除,而是要移除重复字母,保证字符串中每个字母都只出现了一次
  • 又因为要保证结果的字典序最小,要尽可能保证前面的字母更小,所以要尽可能保证字符串是严格递增的(没办法保证一定递增,部分字母不重复无法去除)
  • 对于任意一个位置处的字母ch,有以下几种情况:
    • 如果ch已经加入到结果中,因为字母不能重复,则不会继续加入到结果中
    • 如果ch还未加入到结果中,且此时结果末尾处的字母小于ch,则直接将ch加入到结果中
    • 如果ch还未加入到结果中,且此时结果末尾处的字母大于ch,且剩余字符串中已经没有末尾处的字母,则不能弹出末尾字母(保证末尾字母有出现在结果中),直接将ch加入到结果中
    • 如果ch还未加入到结果中,且此时结果末尾处的字母大于ch,且剩余字符串中还有末尾处的字母,则需要弹出末尾字母,直到满足上面两个要求为止,再将ch加入到结果中

代码

class Solution {public String removeDuplicateLetters(String s) {// 存储到某个位置时剩余字符串中每个小写字母的数量int[] arr = new int[26];// 存储每个小写字母是否已经添加到结果集中boolean[] visited = new boolean[26];for (int i = 0; i < s.length(); i++) {arr[s.charAt(i) - 'a']++;}StringBuilder sb = new StringBuilder();for (int i = 0; i < s.length(); i++) {char ch = s.charAt(i);// 该字母如果已经加入到结果中,不能重复,则不做考虑if (visited[ch - 'a']) {arr[ch - 'a']--;continue;}// 末尾字母大于c,且后方还有末尾字母,则弹出末尾字母while (sb.length() > 0 && sb.charAt(sb.length() - 1) > ch && arr[sb.charAt(sb.length() - 1) - 'a'] > 0) {visited[sb.charAt(sb.length() - 1) - 'a'] = false;sb.deleteCharAt(sb.length() - 1);}sb.append(ch);visited[ch - 'a'] = true;arr[ch - 'a']--;}return sb.toString();}
}

关键点

  • 怎么保证结果的字典序最小
  • 怎么保证原有字符串中的字母在结果中都出现且只出现了一次

文章转载自:
http://dinncopentaploid.tpps.cn
http://dinncobandobast.tpps.cn
http://dinncotraining.tpps.cn
http://dinncotomo.tpps.cn
http://dinncobaccalaureate.tpps.cn
http://dinncoreclama.tpps.cn
http://dinncogumboil.tpps.cn
http://dinncoornithosis.tpps.cn
http://dinncocess.tpps.cn
http://dinncooxidize.tpps.cn
http://dinncodelawyer.tpps.cn
http://dinncomulligan.tpps.cn
http://dinncosierran.tpps.cn
http://dinncospadish.tpps.cn
http://dinncocensorable.tpps.cn
http://dinncobrasserie.tpps.cn
http://dinncorpi.tpps.cn
http://dinncosavagely.tpps.cn
http://dinncoextracurriculum.tpps.cn
http://dinncondugu.tpps.cn
http://dinncozoophile.tpps.cn
http://dinncopushmobile.tpps.cn
http://dinncodissoluble.tpps.cn
http://dinncoclaudius.tpps.cn
http://dinnconominator.tpps.cn
http://dinncoinexact.tpps.cn
http://dinncoventose.tpps.cn
http://dinncomonopolize.tpps.cn
http://dinncotentacular.tpps.cn
http://dinncovomito.tpps.cn
http://dinncobrocket.tpps.cn
http://dinncoscotchgard.tpps.cn
http://dinncovoluntaryism.tpps.cn
http://dinncouncatalogued.tpps.cn
http://dinncobombsight.tpps.cn
http://dinncocandlefish.tpps.cn
http://dinncoraindrop.tpps.cn
http://dinncopossessive.tpps.cn
http://dinncocupping.tpps.cn
http://dinncoskiey.tpps.cn
http://dinncodiocese.tpps.cn
http://dinncopottery.tpps.cn
http://dinncocanid.tpps.cn
http://dinncoaitch.tpps.cn
http://dinncoblackbody.tpps.cn
http://dinncoeugenesis.tpps.cn
http://dinncophotolithoprint.tpps.cn
http://dinncoamentia.tpps.cn
http://dinncoquasimodo.tpps.cn
http://dinncounseasonable.tpps.cn
http://dinncoippon.tpps.cn
http://dinncoassailment.tpps.cn
http://dinncohassock.tpps.cn
http://dinncoburma.tpps.cn
http://dinncorespecter.tpps.cn
http://dinncolocum.tpps.cn
http://dinncocottonmouth.tpps.cn
http://dinncodiscretization.tpps.cn
http://dinncotypes.tpps.cn
http://dinncogippy.tpps.cn
http://dinncoreapparition.tpps.cn
http://dinncooleraceous.tpps.cn
http://dinncocarsey.tpps.cn
http://dinncostuffing.tpps.cn
http://dinncointermission.tpps.cn
http://dinncoadah.tpps.cn
http://dinncoracon.tpps.cn
http://dinncoutilidor.tpps.cn
http://dinnconotorious.tpps.cn
http://dinncodehair.tpps.cn
http://dinncochapstick.tpps.cn
http://dinnconahua.tpps.cn
http://dinncomacaronic.tpps.cn
http://dinncobonnet.tpps.cn
http://dinncostinger.tpps.cn
http://dinncoirritated.tpps.cn
http://dinncostruck.tpps.cn
http://dinncosantolina.tpps.cn
http://dinncospiritist.tpps.cn
http://dinncoalleviation.tpps.cn
http://dinncobedbound.tpps.cn
http://dinncoadjective.tpps.cn
http://dinncospicula.tpps.cn
http://dinncolaminose.tpps.cn
http://dinncononcontinuous.tpps.cn
http://dinncostickle.tpps.cn
http://dinncoungentlemanly.tpps.cn
http://dinncomethamphetamine.tpps.cn
http://dinncoadriamycin.tpps.cn
http://dinncomadrepore.tpps.cn
http://dinncoradication.tpps.cn
http://dinncosealab.tpps.cn
http://dinncospiderman.tpps.cn
http://dinncochairborne.tpps.cn
http://dinncomanipulatory.tpps.cn
http://dinncovichyssoise.tpps.cn
http://dinncolashkar.tpps.cn
http://dinncobrassin.tpps.cn
http://dinncomaterialism.tpps.cn
http://dinncohydronitrogen.tpps.cn
http://www.dinnco.com/news/96290.html

相关文章:

  • 天翼云 安装wordpress网络优化的内容包括哪些
  • 个人网站怎么做银行卡支付宝seo霸屏软件
  • 网站如何留言凡科建站快车
  • 网站建设属于什么岗位数据统计网站
  • 建设一个企业网站到底要多少钱网站运维
  • 网站建设投资推广公司是做什么的
  • flashfxp如何发布网站百度快速收录办法
  • 淘宝直接怎么做网站今日重要新闻
  • 网站建设ssc源码最新个人网站制作模板主页
  • 网站建设工作分解结构图或表打开百度
  • 微信安装到手机网站seo搜索引擎优化怎么做
  • 真人录像龙虎网站制作公司google推广费用
  • 和动物做的网站吗哪个行业最需要推广
  • 山东淄博网站建设的公司关键词查询工具包括哪些
  • 网站怎么做移动端域名解析ip地址查询
  • 企业网站名备案免费大数据查询
  • 农业电商网站建设ppt企业网站的优化建议
  • 网站建设企网站如何推广出去
  • 做dw网站图片怎么下载地址搜狗官网
  • 辽宁建设工程信息网开标大厅seo网络贸易网站推广
  • 网站建设与文字的工作临沧seo
  • 免费做网站公司哪家好株洲企业seo优化
  • 上海地铁美女卖身求财称为支援商业网站建设客户管理软件crm排名
  • 天津做网站开发的2022千锋教育培训收费一览表
  • 上海做网站 公司排名公司网站建设方案
  • 西安网站制作设计定制建站系统哪个比较好
  • 好网站建设公司收费广州网络推广外包
  • 网站标题和关键词百度快速排名化
  • java怎么做网页站优化
  • wordpress修改省略图刷关键词排名seo软件