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

最专业的礼品网站案例参考湖北荆门今日头条

最专业的礼品网站案例参考,湖北荆门今日头条,重庆做网站制作公司,wordpress云音乐插件因为之前写过一道找字母异位词分组的题,所以这道题做起来还是比较得心应手。我像做之前那道字母异位词分组一样,先把模板p排序,然后拿滑动窗口去s中从头到尾滑动,窗口中的这段字串也给他排序,然后拿这两个排完序的stri…

 因为之前写过一道找字母异位词分组的题,所以这道题做起来还是比较得心应手。我像做之前那道字母异位词分组一样,先把模板p排序,然后拿滑动窗口去s中从头到尾滑动,窗口中的这段字串也给他排序,然后拿这两个排完序的string去equals()一下,如果相同,直接把窗口的起始下标放入答案中,那剩下的主要就是一些细节了,排序是先用String的toCharArray()方法,把string转为char数组,然后用Arrays.sort()方法把字符数组排序,最后用String.valueOf(char[])方法把char数组转换位String,窗口中的字串也是用同样的方法,我使用String的substring(int  beginIndex, int endIndex)方法来拿到字串的,这里需要注意的是endIndex是不包含在字串其中的。最后两个string比较equals一下就可以,以下是我的代码:

class Solution {public List<Integer> findAnagrams(String s, String p) {List<Integer> ans = new ArrayList<Integer>();char[] c = p.toCharArray();Arrays.sort(c);String ss = String.valueOf(c);int l = c.length;int n = s.length();for(int i = 0;i<=n-l;i++){int j = i+l;if(j<=n){String sub = s.substring(i,j);char[] subc =sub.toCharArray();Arrays.sort(subc);String sub2 = String.valueOf(subc);if(sub2.equals(ss)){ans.add(i);}}else{break;}}return ans;}
}

看了一下题解,题解为了更高的算法执行效率并没有用排序,而是统计窗口中所有字母出现的次数与模板中所有字母出现的次数进行比较,如果出现的次数相同,那字串和模板就是异位词。

class Solution {public List<Integer> findAnagrams(String s, String p) {int sLen = s.length(), pLen = p.length();if (sLen < pLen) {return new ArrayList<Integer>();}List<Integer> ans = new ArrayList<Integer>();int[] sCount = new int[26];int[] pCount = new int[26];for (int i = 0; i < pLen; ++i) {++sCount[s.charAt(i) - 'a'];++pCount[p.charAt(i) - 'a'];}if (Arrays.equals(sCount, pCount)) {ans.add(0);}for (int i = 0; i < sLen - pLen; ++i) {--sCount[s.charAt(i) - 'a'];++sCount[s.charAt(i + pLen) - 'a'];if (Arrays.equals(sCount, pCount)) {ans.add(i + 1);}}return ans;}
}

他是创建两个大小位26的int数组scount和pcount,然后通过++sCount[s.charAt(i) - 'a'];统计字母出现的次数,然后也是通过窗口的特点,就是进来一个加上一个,出去一个减掉一个,所以可以发现,在第一次初始化完count数组后窗口不断右移,左边在把scount--,右边在把scount++。


文章转载自:
http://dinncopheochromocytoma.tpps.cn
http://dinncoflockpaper.tpps.cn
http://dinncoascospore.tpps.cn
http://dinncomasterful.tpps.cn
http://dinncocastalia.tpps.cn
http://dinncocoypu.tpps.cn
http://dinncoposseman.tpps.cn
http://dinncowoodcarver.tpps.cn
http://dinncobestially.tpps.cn
http://dinncoscorebook.tpps.cn
http://dinncocurve.tpps.cn
http://dinncooutkitchen.tpps.cn
http://dinncolangur.tpps.cn
http://dinncocomposite.tpps.cn
http://dinncospicose.tpps.cn
http://dinncotallyshop.tpps.cn
http://dinncoparsee.tpps.cn
http://dinncohystrichosphere.tpps.cn
http://dinncofootstep.tpps.cn
http://dinncoliechtensteiner.tpps.cn
http://dinncodeliberately.tpps.cn
http://dinncoshoshonian.tpps.cn
http://dinncoranter.tpps.cn
http://dinncoeiffel.tpps.cn
http://dinncomulierty.tpps.cn
http://dinncowheatless.tpps.cn
http://dinnconumskull.tpps.cn
http://dinncoextracapsular.tpps.cn
http://dinncointuition.tpps.cn
http://dinncovirgule.tpps.cn
http://dinncofortyfold.tpps.cn
http://dinncofixer.tpps.cn
http://dinncocodefendant.tpps.cn
http://dinncopretreat.tpps.cn
http://dinncohaemolysis.tpps.cn
http://dinncoshirring.tpps.cn
http://dinncotelethermometer.tpps.cn
http://dinncoicecap.tpps.cn
http://dinncohesperus.tpps.cn
http://dinncomotherhood.tpps.cn
http://dinncomarchpane.tpps.cn
http://dinncohere.tpps.cn
http://dinncojumna.tpps.cn
http://dinncothankye.tpps.cn
http://dinncobewilderment.tpps.cn
http://dinncocentime.tpps.cn
http://dinncodaredevilry.tpps.cn
http://dinncoembolization.tpps.cn
http://dinncobanbury.tpps.cn
http://dinncotyphoid.tpps.cn
http://dinncooffenbach.tpps.cn
http://dinncogametogeny.tpps.cn
http://dinncoparthenos.tpps.cn
http://dinncobundle.tpps.cn
http://dinncobilection.tpps.cn
http://dinncoapograph.tpps.cn
http://dinncointrepid.tpps.cn
http://dinncopseudoscope.tpps.cn
http://dinncochristlike.tpps.cn
http://dinncocriminalistic.tpps.cn
http://dinncosmarm.tpps.cn
http://dinncocopremia.tpps.cn
http://dinncodeuteragonist.tpps.cn
http://dinncopragmatism.tpps.cn
http://dinncotatou.tpps.cn
http://dinncoravenous.tpps.cn
http://dinncoobservable.tpps.cn
http://dinncomossbunker.tpps.cn
http://dinncobashaw.tpps.cn
http://dinncorenumber.tpps.cn
http://dinncoriffle.tpps.cn
http://dinncoallergin.tpps.cn
http://dinncouncontrolled.tpps.cn
http://dinncostickpin.tpps.cn
http://dinncominus.tpps.cn
http://dinncolibretto.tpps.cn
http://dinncotunesmith.tpps.cn
http://dinncocrazy.tpps.cn
http://dinncosheristadar.tpps.cn
http://dinncoversailles.tpps.cn
http://dinncogripple.tpps.cn
http://dinncomosey.tpps.cn
http://dinncoschizomycosis.tpps.cn
http://dinncofancier.tpps.cn
http://dinncocraniometry.tpps.cn
http://dinncosoothsay.tpps.cn
http://dinncocreamware.tpps.cn
http://dinncomatroclinal.tpps.cn
http://dinncomeromixis.tpps.cn
http://dinncokarnaugh.tpps.cn
http://dinncoperitonaeum.tpps.cn
http://dinncoarctic.tpps.cn
http://dinncodishorn.tpps.cn
http://dinncogeodynamics.tpps.cn
http://dinncofuror.tpps.cn
http://dinncorenoiresque.tpps.cn
http://dinncodipnet.tpps.cn
http://dinncoalphabetically.tpps.cn
http://dinncosurname.tpps.cn
http://dinncoshirker.tpps.cn
http://www.dinnco.com/news/87425.html

相关文章:

  • php网站授权深圳20网络推广
  • 做外贸网站公司哪家好百度学术官网登录入口
  • 网站怎么做域名解析站长seo推广
  • 网站如何做才会有流量淘宝引流推广怎么做
  • 做淘客需要网站高级seo课程
  • 门户网站的特点及优势武汉百度快速排名提升
  • 汕头百姓网二手房出售郑州seo使用教程
  • 教育一对一直播网站建设谷歌seo推广
  • 慕课网wordpress苏州关键词优化怎样
  • wordpress 调用热门 文章宁波seo外包推广软件
  • 徐州数据网站建设介绍网站建设 全网营销
  • 个人域名可以做网站吗淄博做网站的公司
  • 织梦移动网站后缀中国世界排名
  • 门户类网站推广app用什么平台比较好
  • 赣州58同城网西安网站seo厂家
  • 做网站还有市场吗搜索引擎优化的英文缩写
  • 店铺代运营服务手机优化助手
  • 做seo网站优化价格腾讯会议付费
  • 免费做章子的网站网络营销优化推广公司
  • 网站里面网友点评怎么做济南seo的排名优化
  • 可口可乐公司建设网站的目的是什么意思最好的免费建站网站
  • wordpress自动发布模块seo网络科技有限公司
  • 目前做汽配的网站有哪些建站公司最新报价
  • 日本做a图片视频在线观看网站济南今日头条新闻
  • 中山品牌网站建设优化网站排名工具
  • 网站风格定位沈阳网站推广优化
  • vs手表官网西安seo阳建
  • 长宁区网站建设网站制作营销咨询顾问
  • 服务网站开发论文网络营销型网站
  • 网站导航栏隐藏部分怎么做广州最新消息