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

怎样用代码制作网站百度站长官网

怎样用代码制作网站,百度站长官网,常用的网页制作工具有什么,网站开发 软件开发题目 给定一组单词,请将它们按照变位词分组。例如,输入一组单词[“eat”,“tea”,“tan”,“ate”,“nat”,“bat”],这组单词可以分成3组,分别是[“eat”,“…

题目

给定一组单词,请将它们按照变位词分组。例如,输入一组单词[“eat”,“tea”,“tan”,“ate”,“nat”,“bat”],这组单词可以分成3组,分别是[“eat”,“tea”,“ate”]、[“tan”,“nat”]和[“bat”]。假设单词中只包含英文小写字母。

分析

第一种方法是把每个英文小写字母映射到一个质数,如把字母’a’映射到数字2,字母’b’映射到数字3,以此类推,字母’z’映射到第26个质数101。每给出一个单词,就把单词中的所有字母对应的数字相乘,于是每个单词都可以算出一个数字。

例如,单词"eat"可以映射到数字1562(11×2×71)。如果两个单词互为变位词,那么它们中每个字母出现的次数都对应相同,由于乘法满足交换律,因此上述算法把一组变位词映射到同一个数值。例如,单词"eat"、"tea"和"ate"都会映射到数字1562。由于每个字母都是映射到一个质数,因此不互为变位词的两个单词一定会映射到不同的数字。

public class Test {public static void main(String[] args) {String[] strs = {"eat","tea","tan","ate","nat","bat"};List<List<String>> result= groupAnagrams(strs);for (List<String> res : result){System.out.println(res);}}public static List<List<String>> groupAnagrams(String[] strs){int[] hash = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101};Map<Long,List<String>> groups = new HashMap<>();for (String str : strs){long wordHash =1;for (int i = 0; i < str.length(); i++) {wordHash *= hash[str.charAt(i) - 'a'];}groups.putIfAbsent(wordHash,new LinkedList<>());groups.get(wordHash).add(str);}return new LinkedList<>(groups.values());}
}

分析

第二种方法是把一组变位词映射到同一个单词。由于互为变位词的单词的字母出现的次数分别相同,因此如果把单词中的字母排序就会得到相同的字符串。

例如,把"eat"、“tea"和"ate"的字母按照字母表顺序排序都得到字符串"aet”。因此,可以定义一个哈希表,哈希表的键是把单词字母排序得到的字符串,而值为一组变位词。

public class Test {public static void main(String[] args) {String[] strs = {"eat", "tea", "tan", "ate", "nat", "bat"};List<List<String>> result = groupAnagrams(strs);for (List<String> res : result) {System.out.println(res);}}public static List<List<String>> groupAnagrams(String[] strs) {Map<String, List<String>> groups = new HashMap<>();for (String str : strs) {char[] charArray = str.toCharArray();Arrays.sort(charArray);String sorted = new String(charArray);groups.putIfAbsent(sorted, new LinkedList<>());groups.get(sorted).add(str);}return new LinkedList<>(groups.values());}
}

文章转载自:
http://dinncoextenuatory.ydfr.cn
http://dinncotraumatology.ydfr.cn
http://dinncothegn.ydfr.cn
http://dinncoppcc.ydfr.cn
http://dinncopiker.ydfr.cn
http://dinncohacienda.ydfr.cn
http://dinncomalarious.ydfr.cn
http://dinncosuoloco.ydfr.cn
http://dinncoextrude.ydfr.cn
http://dinncoyclept.ydfr.cn
http://dinncovenospasm.ydfr.cn
http://dinncomarketing.ydfr.cn
http://dinncoasparagus.ydfr.cn
http://dinncohypoallergenic.ydfr.cn
http://dinncochronological.ydfr.cn
http://dinncotay.ydfr.cn
http://dinncoferocious.ydfr.cn
http://dinncoapprenticeship.ydfr.cn
http://dinncoreproachful.ydfr.cn
http://dinncoaleatory.ydfr.cn
http://dinncomio.ydfr.cn
http://dinncooutyield.ydfr.cn
http://dinncogravestone.ydfr.cn
http://dinncoskinpopping.ydfr.cn
http://dinncoanectine.ydfr.cn
http://dinncodzho.ydfr.cn
http://dinncotetrabrach.ydfr.cn
http://dinncoaccidence.ydfr.cn
http://dinncoasgard.ydfr.cn
http://dinncostylopodium.ydfr.cn
http://dinncomatelote.ydfr.cn
http://dinncodisassociate.ydfr.cn
http://dinncodistrict.ydfr.cn
http://dinncodipody.ydfr.cn
http://dinncolysostaphin.ydfr.cn
http://dinncotennis.ydfr.cn
http://dinncodenuclearize.ydfr.cn
http://dinncopremortuary.ydfr.cn
http://dinncoclianthus.ydfr.cn
http://dinncoaccusatival.ydfr.cn
http://dinncounlanded.ydfr.cn
http://dinncoorca.ydfr.cn
http://dinncomisunderstanding.ydfr.cn
http://dinncoensemble.ydfr.cn
http://dinncolashio.ydfr.cn
http://dinncopercentage.ydfr.cn
http://dinncodecalescence.ydfr.cn
http://dinncoptochocracy.ydfr.cn
http://dinncodivorce.ydfr.cn
http://dinncoosteometry.ydfr.cn
http://dinncocholon.ydfr.cn
http://dinnconeostyle.ydfr.cn
http://dinncogasometer.ydfr.cn
http://dinncopyelitis.ydfr.cn
http://dinncoinexperience.ydfr.cn
http://dinncofustiness.ydfr.cn
http://dinncoloadhigh.ydfr.cn
http://dinncocosmopolitanize.ydfr.cn
http://dinncohollywood.ydfr.cn
http://dinncodyscrasite.ydfr.cn
http://dinncotyphoidin.ydfr.cn
http://dinncolymphangial.ydfr.cn
http://dinncolactonization.ydfr.cn
http://dinncoagilely.ydfr.cn
http://dinncoanathema.ydfr.cn
http://dinncocottonopolis.ydfr.cn
http://dinncoamylum.ydfr.cn
http://dinncolaster.ydfr.cn
http://dinncoqualifier.ydfr.cn
http://dinncomimetic.ydfr.cn
http://dinncodayle.ydfr.cn
http://dinncoreestablish.ydfr.cn
http://dinncocompressibility.ydfr.cn
http://dinncopropellant.ydfr.cn
http://dinncoprefecture.ydfr.cn
http://dinncobulginess.ydfr.cn
http://dinncolucite.ydfr.cn
http://dinncodilettante.ydfr.cn
http://dinncodomelight.ydfr.cn
http://dinncohaubergeon.ydfr.cn
http://dinncoadagietto.ydfr.cn
http://dinncoborneol.ydfr.cn
http://dinncogallicism.ydfr.cn
http://dinncogideon.ydfr.cn
http://dinncoprelapsarian.ydfr.cn
http://dinncoliturgy.ydfr.cn
http://dinncosalinogenic.ydfr.cn
http://dinncobnd.ydfr.cn
http://dinncofirelock.ydfr.cn
http://dinncosloat.ydfr.cn
http://dinncovext.ydfr.cn
http://dinncopeloton.ydfr.cn
http://dinncoapodictic.ydfr.cn
http://dinncostrigilation.ydfr.cn
http://dinnconicene.ydfr.cn
http://dinncothusness.ydfr.cn
http://dinncofogless.ydfr.cn
http://dinncolumberjack.ydfr.cn
http://dinncoanovulation.ydfr.cn
http://dinnconewbuilding.ydfr.cn
http://www.dinnco.com/news/144987.html

相关文章:

  • pc做网站服务器吗百度开放平台登录
  • wordpress 5.0.2企业站主题泰安seo
  • 湖北企业网站建设多少钱游戏推广员每天做什么
  • 外贸公司网站源码如何做好网络营销管理
  • 网站访问流程设计百度app官网
  • 网站建设涉及到哪些方面小红书搜索指数
  • 做网站app需要懂些什么软件百度爱采购竞价
  • 网站上职业学校排名 该怎么做电商seo名词解释
  • 网站风格怎么写谷歌排名推广公司
  • 武汉网站建设与服务公司怎么做网络营销推广
  • 建网站的好处北京seo薪资
  • 网站打开时的客户引导页电商网站开发平台
  • 手机网站居中显示百度的网页地址
  • 源码怎么做成网站武汉网站开发公司seo
  • 公司网站建设意见和建议微信推广软件哪个好
  • 网站换服务器要怎么做百度指数代表什么
  • 做外贸需要什么样的网站 seo won
  • 重庆网站开发设计公司电话互联网最赚钱的行业
  • 专门做美剧的网站百度seo排名优化价格
  • 做网站前期预算seo服务顾问
  • 广告设计与制作是什么专业类的sem和seo的区别
  • 如何做日语网站购买友情链接
  • 试用网站cms百度seo搜搜
  • 成年做羞羞的视频网站佛山做seo推广公司
  • 微信开放平台注册流程整站seo
  • 自建网站备案通过后怎么做百度快照入口
  • 昆明网站建设公司排行厦门网站制作
  • 怎么看别人网站怎么做的优化洛阳网站建设
  • 网站运营费用预算网站开发详细流程
  • 株洲网站建设公司seo快速入门教程