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

手机 网站 系统微商软件自助商城

手机 网站 系统,微商软件自助商城,千万别做网络管理员,seo如何优化排名文章目录 Find And Replace in String 字符串中的查找与替换问题描述#xff1a;分析代码排序模拟 Tag Find And Replace in String 字符串中的查找与替换 问题描述#xff1a; 你会得到一个字符串 s (索引从 0 开始)#xff0c;你必须对它执行 k 个替换操作。替换操作以三… 文章目录 Find And Replace in String 字符串中的查找与替换问题描述分析代码排序模拟 Tag Find And Replace in String 字符串中的查找与替换 问题描述 你会得到一个字符串 s (索引从 0 开始)你必须对它执行 k 个替换操作。替换操作以三个长度均为 k 的并行数组给出indices, sources, targets。 要完成第 i 个替换操作: 检查 子字符串 sources[i] 是否出现在 原字符串 s 的索引 indices[i] 处。如果没有出现 什么也不做 。如果出现则用 targets[i] 替换 该子字符串。 例如如果 s abcd indices[i] 0 , sources[i] ab targets[i] eee 那么替换的结果将是 eeecd 。 所有替换操作必须 同时 发生这意味着替换操作不应该影响彼此的索引。测试用例保证元素间不会重叠 。 例如一个 s abc indices [0,1] sources [abbc] 的测试用例将不会生成因为 ab 和 bc 替换重叠。 在对 s 执行所有替换操作后返回 结果字符串 。 子字符串 是字符串中连续的字符序列。 1 s . l e n g t h 1000 k i n d i c e s . l e n g t h s o u r c e s . l e n g t h t a r g e t s . l e n g t h 1 k 100 0 i n d i c e s [ i ] s . l e n g t h 1 s o u r c e s [ i ] . l e n g t h , t a r g e t s [ i ] . l e n g t h 50 s 仅由小写英文字母组成 s o u r c e s [ i ] 和 t a r g e t s [ i ] 仅由小写英文字母组成 1 s.length 1000\\ k indices.length sources.length targets.length\\ 1 k 100\\ 0 indices[i] s.length\\ 1 sources[i].length, targets[i].length 50\\ s 仅由小写英文字母组成\\ sources[i] 和 targets[i] 仅由小写英文字母组成 1s.length1000kindices.lengthsources.lengthtargets.length1k1000indices[i]s.length1sources[i].length,targets[i].length50s仅由小写英文字母组成sources[i]和targets[i]仅由小写英文字母组成 分析 模拟类型的问题 直接的想法就是依次遍历遇到一个索引进行比较如果于 s o u r c e [ i ] source[i] source[i]相同就要替换成为 t [ i ] t[i] t[i]. 当遇到索引 i d x i n d [ i ] idx ind[i] idxind[i] l s s o u r c e [ i ] . l e n g t h ls source[i].length lssource[i].length.即 s [ i d x : i d x l s − 1 ] s o u r c e [ i ] s[idx:idxls-1]source[i] s[idx:idxls−1]source[i]是否相等。 如果相等 s [ i d x : i d x l s − 1 ] s[idx:idxls-1] s[idx:idxls−1]就需要被替换。因为有限制所以不会出现重叠的现象。此时 s [ i d x l s ] s[idxls] s[idxls]就是未被替换的字符位置它和下一个待比较的索引位置的关系一定是 i d x l s n e x t i d x idxlsnextidx idxlsnextidx. 所以在2个待比较的索引之间未被替换的字符串的长度是0,这一部分就需要加入到结果中。 如果不相等那么 s [ i d x : n e x t i d x − 1 ] s[idx:nextidx-1] s[idx:nextidx−1]的字符串就会全部加入结果中。 模拟 这个思路是以待比较的索引从小到大的排列并且以索引数组为遍历目标进行模拟。 因此需要对原始的三个数组进行预处理即进行索引排序。 代码 排序模拟 class Solution {public String findReplaceString(String s, int[] indices, String[] sources, String[] targets) {StringBuilder sb new StringBuilder();char[] arr s.toCharArray();int n indices.length;int len arr.length;Integer[] indarr new Integer[n];for(int i0;in;i) indarr[i] i;Arrays.sort(indarr,(a,b)-{return indices[a]-indices[b];});int end 0;for(int i0;in;i){int idx indices[indarr[i]];String s1 sources[indarr[i]];String t1 targets[indarr[i]];int l1 s1.length(); if(check(idx,arr,s1)){if(endidx){ sb.append(s.substring(end,idx));} sb.append(t1);end idxl1;}else{int nx i1n?indices[indarr[i1]]:len;if(idxnx) continue; sb.append(s.substring(end,idx));sb.append(s.substring(idx,nx));end nx;} } if(endlen)sb.append(s.substring(end,len));return sb.toString();}public boolean check(int idx,char[] arr,String s){int ls s.length(),n arr.length;int l1 n-idx; if(l1ls) return false;int ind 0;for(int i idx;iidxls;i,ind){ if(arr[i]!s.charAt(ind)) return false; }return true; } }时间复杂度 O ( N M l o g M ) O(NMlogM ) O(NMlogM) 空间复杂度 O ( N M L ) O(NML) O(NML) 还有一种线性的思路S的长度是N那么就有可能会在N个位置上进行替换操作。有空再写 Tag Array Sort String
http://www.yutouwan.com/news/176906/

相关文章:

  • 怎么看一个网站是用模板什么做的wordpress内核文件夹
  • 苏州做网站公司选苏州聚尚网络2016优秀网站设计
  • wordpress中文版源码下载电子商务seo招聘
  • 海东高端网站建设价格新丝路网站建设
  • 深圳拼团网站建设开发app和微网站有哪些功能
  • qq上如何做文学网站做ppt模板网站有哪些内容
  • 网站浏览器兼容性如何建设专业化的网站
  • 做网站好还是网页好丽之鑫科技网站后台怎么做
  • 门户网站建设工作总结甘肃住房建设厅的网站
  • 正确认识部门网站建设如何建网站平台
  • 网站开发项目简单描述网站建设演讲稿
  • 有什么做兼职的好网站西安+医疗网站建设
  • 有什么设计logo网站宠物网站建设目标
  • 网站开发实用技术第2版公司微网站怎么做的
  • 做软件下载网站违法吗如何设计一个购物网站
  • 都什么企业需要网站吗建站网站教程
  • 四川网站建设营业执照怎么年审
  • 网店推广实训系统seo建站教学
  • 网站产品类别顺序如果修改localhost怎么做网站
  • 苏州外贸公司网站建设流程图Wordpress500页面
  • 网站建站查询app推广方案策划
  • 黄石网站建设维护做一个网站成本要多少钱
  • opencart网站建设虎丘苏州网站建设
  • 黄陂区建设招标网站网站模板怎么修改成可视化
  • 网站设计费报价表巩义便宜网站建设公司
  • wordpress建电商网站网站开发毕业设计开课题目
  • 网站制作窍门2016做网站
  • 做网站设计答辩问题个人开发什么软件挣钱
  • 新手建站论坛重庆市公司网站备案在哪了
  • 二手域名交易平台网站编辑做seo好做吗