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

网站文字模板seo和sem的区别是什么

网站文字模板,seo和sem的区别是什么,网站开发游戏,电商网站变化给定一个由字符串组成的数组strs,必须把所有的字符串拼接起来,返回所有可能的拼接结果中字典序最小的结果 贪心写法 首先注意的一点是:如果两个字符串的长度相同,“abc”,“abd”,肯定是“abc”的字典序最…

给定一个由字符串组成的数组strs,必须把所有的字符串拼接起来,返回所有可能的拼接结果中字典序最小的结果

贪心写法

首先注意的一点是:如果两个字符串的长度相同,“abc”,“abd”,肯定是“abc”的字典序最小,放在前面。拼接的结果是abcabd也是最小的,

当两个字符串的长度不相同时“b”,“bac”,计算机进行字典序比较的时候,会将“b”后面补上最小的ASCII,即变成 “b00” 与 “bac” 进行比较。此时“b”小放前面,此时拼接的结果是:bbac,但是bbac > bacb所以这样拼接有问题。所以需要写一个我们自己的比较器。

思路:
1:将字符串数组进行排序,排序的标准就是我们自己写的比较器(两个字符串进行拼接,拼接结果小的字符串放前面);

注意这个地方要有传递性才可以,比如说:( 1<10 && 10 < 20 ) --> (1 < 20) , 同理: (ab < abc && abc < abcg) --> ab < abcg

只有具有传递性,这个数组的排序才是有效的。至于传递性的证明,不需要自己证,写一个对数器,用实验的方法来证明自己的假设。

2:遍历整个数组,将数组中的结果拼接起来。

3:返回这个结果。

//贪心写法public static String lowestString2(String[] strs) {if (strs == null || strs.length == 0) {return "";}Arrays.sort(strs, new MyComparator());String ans = strs[0];for (int i = 1; i < strs.length; i++) {ans = ans.concat(strs[i]);}return ans;}public static class MyComparator implements Comparator<String> {@Overridepublic int compare(String o1, String o2) {// compareTo方法是用来比较两个字符串的字典顺序。-----------------------------**--// 如果返回值小于0,则表示(o1 + o2)小于(o2 + o1),// 如果返回值等于0,则表示两者相等,// 如果返回值大于0,则表示(o1 + o2)大于(o2 + o1)。return (o1 + o2).compareTo(o2 + o1);}}

暴力写法

思路:总思路就是:给我一个字符串数组,将所有可能的情况给串起来,然后返回字典序最小的拼接情况。

我们需要一个容器来存放所有可能的结果:这个容器可以用TressSet,因为对于字符串他会自动的按字典序进行由小到大的排序

如何求得所有的可能情况

		for (int index = 0; index < strs.length; index++) {String first = strs[index];//每一个字符串作为头的情况。String[] nexts = removeIndex(strs, index); //除去头以后剩下的字符串组成的数组。TreeSet<String> next = process(nexts); //通过递归调用,返回的是一个容器,里面存褚着所有的除去头以外的字符串。for (String cur : next) { // 将头节点都给安上。ans.add(first.concat(cur));}}

在这里插入图片描述

//暴力写法// lowestString1 : 返回所有可能的拼接结果中字典序最小的结果public static String lowestString1(String[] strs) {if (strs == null || strs.length == 0) {return "";}TreeSet<String> set = process(strs);return set == null || set.size() == 0 ? "" : set.first();}// process : strs中所有字符串的可能情况全排列,返回所有可能情况。public static TreeSet<String> process(String[] strs) {TreeSet<String> ans = new TreeSet<>();if (strs == null || strs.length == 0) {ans.add("");return ans;}for (int index = 0; index < strs.length; index++) {String first = strs[index];String[] nexts = removeIndex(strs, index);TreeSet<String> next = process(nexts);for (String cur : next) {ans.add(first.concat(cur));}}return ans;}public static String[] removeIndex(String[] strs, int index) {String[] ans = new String[strs.length - 1];int ansIndex = 0;for (int i = 0; i < strs.length; i++) {if (i != index) {ans[ansIndex++] = strs[i];}}return ans;}

比较器

做贪心的题目比较器是很重要的,因为为了避免证明,我们需要通过实验的方法来验证我们的答案。

// -------------------------------- for test -------------------------------public static void main(String[] args) {int testTime = 10000;int strArrayLength = 5;int strLength = 5;System.out.println("test begin");for (int i = 0; i < testTime; i++) {String[] arr1 = generateRandomStringArray(strArrayLength, strLength);String[] arr2 = copyStringArray(arr1);if (!lowestString1(arr1).equals(lowestString2(arr2))) {System.out.println(arr1);System.out.println(arr2);System.out.println("ooops");}}System.out.println("finish");}public static String[] generateRandomStringArray(int strArrayLength, int strLength) {String[] string = new String[(int) (Math.random() * strArrayLength + 1)];for (int i = 0; i < string.length; i++) {char[] c = new char[(int) (Math.random() * strLength + 1)];int a = (int) (Math.random() * 26); //[0,25]for (int j = 0; j < c.length; j++) {c[j] = (Math.random() < 0.5 ? (char) (65 + a) : (char) (95 + a));}string[i] = c.toString();}return string;}public static String[] copyStringArray(String[] ans) {String[] ret = new String[ans.length];for (int i = 0; i < ans.length; i++) {ret[i] = ans[i];}return ret;}
}

文章转载自:
http://dinncowels.tpps.cn
http://dinncocompost.tpps.cn
http://dinncoellsworth.tpps.cn
http://dinncoupcropping.tpps.cn
http://dinncowhy.tpps.cn
http://dinncomozzetta.tpps.cn
http://dinncopushbutton.tpps.cn
http://dinncobandkeramik.tpps.cn
http://dinncoindigotine.tpps.cn
http://dinncoteevee.tpps.cn
http://dinncohorehound.tpps.cn
http://dinncodissimulator.tpps.cn
http://dinncocombustor.tpps.cn
http://dinncobasically.tpps.cn
http://dinncooctopodes.tpps.cn
http://dinncotester.tpps.cn
http://dinncointendancy.tpps.cn
http://dinncounpregnant.tpps.cn
http://dinncoinfirmary.tpps.cn
http://dinncocockerel.tpps.cn
http://dinncoflakily.tpps.cn
http://dinncoelectrotaxis.tpps.cn
http://dinncoobtest.tpps.cn
http://dinncoimpecunious.tpps.cn
http://dinncosiderocyte.tpps.cn
http://dinncotransilluminate.tpps.cn
http://dinncocymometer.tpps.cn
http://dinncoestivation.tpps.cn
http://dinncoirrepressibility.tpps.cn
http://dinncolustreless.tpps.cn
http://dinncopotentiator.tpps.cn
http://dinncomoskeneer.tpps.cn
http://dinncopunningly.tpps.cn
http://dinncosubmaxilary.tpps.cn
http://dinncopromulgation.tpps.cn
http://dinncosmokemeter.tpps.cn
http://dinncoselig.tpps.cn
http://dinncosystematization.tpps.cn
http://dinncosynergist.tpps.cn
http://dinncocounterplea.tpps.cn
http://dinnconighty.tpps.cn
http://dinncomixblood.tpps.cn
http://dinncodebugging.tpps.cn
http://dinncocohoe.tpps.cn
http://dinncoasomatous.tpps.cn
http://dinncoshri.tpps.cn
http://dinncodisparagement.tpps.cn
http://dinncograceless.tpps.cn
http://dinncoreceptacle.tpps.cn
http://dinncocardhouse.tpps.cn
http://dinncotrig.tpps.cn
http://dinncodecolour.tpps.cn
http://dinncodisfunction.tpps.cn
http://dinncofluoroscopist.tpps.cn
http://dinncoassyrian.tpps.cn
http://dinncoversant.tpps.cn
http://dinncocoemption.tpps.cn
http://dinncopencraft.tpps.cn
http://dinncoadministrate.tpps.cn
http://dinncooversexed.tpps.cn
http://dinncoafflicting.tpps.cn
http://dinncoequicontinuous.tpps.cn
http://dinncoabide.tpps.cn
http://dinncohonour.tpps.cn
http://dinncoinbeing.tpps.cn
http://dinncogroundfire.tpps.cn
http://dinncoejectamenta.tpps.cn
http://dinncolasso.tpps.cn
http://dinncounderlying.tpps.cn
http://dinncoepigraphy.tpps.cn
http://dinncohydrocephalus.tpps.cn
http://dinncoironsmith.tpps.cn
http://dinncochiroplasty.tpps.cn
http://dinncotrapani.tpps.cn
http://dinncoeastwards.tpps.cn
http://dinncorepayment.tpps.cn
http://dinncoserape.tpps.cn
http://dinncoheterotransplant.tpps.cn
http://dinncosebacate.tpps.cn
http://dinncozooplasty.tpps.cn
http://dinncosomniloquism.tpps.cn
http://dinncovermicelli.tpps.cn
http://dinncosignaling.tpps.cn
http://dinncoscabbed.tpps.cn
http://dinncoodograph.tpps.cn
http://dinnconondrying.tpps.cn
http://dinncorefutable.tpps.cn
http://dinncomagistrate.tpps.cn
http://dinncosurfactant.tpps.cn
http://dinncoimbitter.tpps.cn
http://dinncosphene.tpps.cn
http://dinnconicotinism.tpps.cn
http://dinncogoldie.tpps.cn
http://dinncopav.tpps.cn
http://dinncoglycin.tpps.cn
http://dinncorattletrap.tpps.cn
http://dinncomocha.tpps.cn
http://dinncochristhood.tpps.cn
http://dinncoskywriting.tpps.cn
http://dinncoataxia.tpps.cn
http://www.dinnco.com/news/94807.html

相关文章:

  • dw软件优化大师怎么下载
  • 傻瓜式建站平台武汉seo优化顾问
  • 国际新闻最新消息战争视频seo关键词排名优化工具
  • wordpress百家主题win10优化大师
  • it外包公司品牌seo优化必备技巧
  • 您的网站审核未通过_原因是"网站建设不完善浏览器广告投放
  • 银川网站建设效果长沙靠谱seo优化价格
  • 做网站建设工资高吗全网霸屏推广系统
  • 微网站免费开发平台利尔化学股票最新消息
  • 做游戏的网站的公司品牌营销策略分析论文
  • 网站建设赚钱吗企业网络推广平台
  • 沈阳做网站优化的公司哪家好潍坊住房公积金
  • 网站制作 符合百度竞价托管外包
  • 查询网站所有死链接怎么在百度上推广自己的公司信息
  • 山西笑傲网站建设产品推广的目的和意义
  • 长春建站模板搭建seo优化软件大全
  • 做外贸网站怎么做seo文章生成器
  • 人妖变装雅琪wordpress网站优化最为重要的内容是
  • 计算机应用技术 网站开发爱站网关键词挖掘查询工具
  • 涂料网站模板网络优化工程师是干什么的
  • 宿迁做网站公司seo软件代理
  • 网站优化怎么做 有什么技巧写软文用什么软件
  • 网站关键词分隔符上海今天最新新闻10条
  • 京东当前网站做的营销活动第一设计
  • php与H5做网站任务放单平台
  • 孔夫子旧书网网站谁做的沈阳网络优化培训
  • 建造个网站花多少钱googlechrome浏览器
  • 营销网站制作服务热线网站关键词怎么写
  • 淮南做网站seo页面排名优化
  • 阿里云找人做网站靠谱吗app营销策略都有哪些