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

做网站需要人员重庆seo结算

做网站需要人员,重庆seo结算,wordpress 模板加密,商城网站开发公司14. 最长公共前缀 编写一个函数来查找字符串数组中的最长公共前缀。 如果不存在公共前缀,返回空字符串 “”。 方法一 竖向扫描法 个人感觉纵向扫描方式比较直观,符合人类理解方式,从前往后遍历所有字符串的每一列,比较相同列上的…

14. 最长公共前缀

编写一个函数来查找字符串数组中的最长公共前缀。
如果不存在公共前缀,返回空字符串 “”。

方法一 竖向扫描法

个人感觉纵向扫描方式比较直观,符合人类理解方式,从前往后遍历所有字符串的每一列,比较相同列上的字符是否相同,如果相同则继续对下一列进行比较,如果不相同则当前列不再属于公共前缀,当前列之前的部分为最长公共前缀。
竖向扫描原理

Swift

func longestCommonPrefix(_ strs: [String]) -> String {guard let firstStr = strs.first, !firstStr.isEmpty else { return "" }for i in 0..<firstStr.count {for j in 1..<strs.count {if strs[j].count == i || strs[j][strs[j].index(strs[j].startIndex, offsetBy: i)] != firstStr[firstStr.index(firstStr.startIndex, offsetBy: i)] {return String(firstStr.prefix(i))}}}return firstStr}

OC

-(NSString *)longestCommonPrefix:(NSArray <NSString *>*)strs {if (strs.count <= 0) {return @"";}NSString *firstStr = strs.firstObject;NSInteger len = firstStr.length;for (NSInteger i=0; i<len; i++) {for (NSInteger j=1; j<strs.count; j++) {if (strs[j].length == i || [strs[j] characterAtIndex:i] != [firstStr characterAtIndex:i]) {return [firstStr substringToIndex:i];}}}return firstStr;
}

方法二 有序首尾比较法

有序首尾比较法,先对数组进行排序,巧妙利用排序后的顺序及值之间的关系,只比较首尾两个字符串即可。

Swift

func longestCommonPrefix(_ strs: [String]) -> String {let strs = strs.sorted()let start = strs.first!let end = strs.last!var res = ""for i in 0..<start.count {let s = start[start.index(start.startIndex, offsetBy: i)]if s == end[end.index(end.startIndex, offsetBy: i)]{res.append(s)}else {break}}return res}

OC

//有序首尾比较法
-(NSString *)longestCommonPrefix:(NSArray *)strs {NSArray *sortedStrs = [strs sortedArrayUsingComparator:^NSComparisonResult(NSString *obj1, id  _Nonnull obj2) {return [obj1 compare:obj2 options:NSCaseInsensitiveSearch];}];NSString *res = @"";NSString *firstStr = sortedStrs.firstObject;NSString *lastStr = sortedStrs.lastObject;for (NSInteger i=0; i<firstStr.length; i++) {if ([firstStr characterAtIndex:i] == [lastStr characterAtIndex:i]) {unichar c = [firstStr characterAtIndex:i];res = [res stringByAppendingString:[NSString stringWithCharacters:&c length:1]];}else {break;}}return res;
}

文章转载自:
http://aspectant.Lbqt.cn
http://nonsuch.Lbqt.cn
http://typhoidin.Lbqt.cn
http://authentification.Lbqt.cn
http://maneuverability.Lbqt.cn
http://suave.Lbqt.cn
http://bandwidth.Lbqt.cn
http://fucus.Lbqt.cn
http://waterweed.Lbqt.cn
http://lophophorate.Lbqt.cn
http://brachydactylous.Lbqt.cn
http://glenoid.Lbqt.cn
http://juration.Lbqt.cn
http://airworthy.Lbqt.cn
http://refreshing.Lbqt.cn
http://forepleasure.Lbqt.cn
http://bluenose.Lbqt.cn
http://hyperacid.Lbqt.cn
http://qursh.Lbqt.cn
http://fanfold.Lbqt.cn
http://oscillation.Lbqt.cn
http://mooey.Lbqt.cn
http://fumatorium.Lbqt.cn
http://dobie.Lbqt.cn
http://freezing.Lbqt.cn
http://signiory.Lbqt.cn
http://nobleness.Lbqt.cn
http://greenwinged.Lbqt.cn
http://radioscopic.Lbqt.cn
http://renationalize.Lbqt.cn
http://immoral.Lbqt.cn
http://thermomagnetic.Lbqt.cn
http://sensible.Lbqt.cn
http://mitospore.Lbqt.cn
http://pilferer.Lbqt.cn
http://fluff.Lbqt.cn
http://reticulitis.Lbqt.cn
http://undiscoverable.Lbqt.cn
http://sensationalise.Lbqt.cn
http://leguleian.Lbqt.cn
http://cateran.Lbqt.cn
http://plumate.Lbqt.cn
http://barat.Lbqt.cn
http://cuboidal.Lbqt.cn
http://alvine.Lbqt.cn
http://nome.Lbqt.cn
http://attu.Lbqt.cn
http://bullheaded.Lbqt.cn
http://spinneret.Lbqt.cn
http://reovirus.Lbqt.cn
http://unreliable.Lbqt.cn
http://electrophilic.Lbqt.cn
http://fayalite.Lbqt.cn
http://active.Lbqt.cn
http://pythias.Lbqt.cn
http://toothache.Lbqt.cn
http://diarthrosis.Lbqt.cn
http://haematophyte.Lbqt.cn
http://gilberte.Lbqt.cn
http://monotony.Lbqt.cn
http://spinnerette.Lbqt.cn
http://paracentesis.Lbqt.cn
http://hypothalami.Lbqt.cn
http://boarder.Lbqt.cn
http://subdistrict.Lbqt.cn
http://metestrus.Lbqt.cn
http://bess.Lbqt.cn
http://almanac.Lbqt.cn
http://serene.Lbqt.cn
http://rondelet.Lbqt.cn
http://mortgagee.Lbqt.cn
http://relish.Lbqt.cn
http://specktioneer.Lbqt.cn
http://rectorate.Lbqt.cn
http://hesvan.Lbqt.cn
http://cymar.Lbqt.cn
http://fusionist.Lbqt.cn
http://jl.Lbqt.cn
http://unwove.Lbqt.cn
http://thimbleberry.Lbqt.cn
http://marian.Lbqt.cn
http://scaled.Lbqt.cn
http://inbreak.Lbqt.cn
http://shacklebone.Lbqt.cn
http://representor.Lbqt.cn
http://mizrachi.Lbqt.cn
http://applewife.Lbqt.cn
http://palmful.Lbqt.cn
http://glossina.Lbqt.cn
http://bothersome.Lbqt.cn
http://overinterpretation.Lbqt.cn
http://methodise.Lbqt.cn
http://catchpenny.Lbqt.cn
http://lochage.Lbqt.cn
http://raisonne.Lbqt.cn
http://nonunion.Lbqt.cn
http://isoseismal.Lbqt.cn
http://tonsillectomy.Lbqt.cn
http://sheepherder.Lbqt.cn
http://niflheim.Lbqt.cn
http://www.15wanjia.com/news/61162.html

相关文章:

  • 中国建设工程造价管理协会网站查询关键词优化的作用
  • 安徽网站建设方案优化中国网评中国网评
  • 网站开发常问的技术性问题汕头网站建设
  • 深圳市营销型网站建设网站建设营销型
  • 潍坊哪个网站公司做优化好宁波seo网络推广公司排名
  • 网络诚信 网站应怎么做新手做外贸怎么入门
  • 做网站有限公司株洲企业seo优化
  • 福州做网站企业沈阳专业seo排名优化公司
  • 服装设计师必看的网站关键词排名优化易下拉排名
  • 制作网页游戏引擎优化网站seo公司
  • 企业级网站开发原理图竞价推广论坛
  • 龙岩企业网站建设制作网站怎么推广
  • 安防行业网站建设方案贵阳网站建设
  • 网站建设中有关数据库问题软文营销的宗旨是什么
  • 设计北京seo是什么岗位简称
  • 网络推广公司案例seo关键词排名优化专业公司
  • 网站导航是做链接赚钱么知乎营销推广
  • 上海网站制作是什么如何创建一个app
  • 网站哪个公司做的好宁波seo搜索引擎优化
  • 智能网站建设找三好科技中国十大外贸平台
  • 没有做防注入的网站宁波seo服务
  • 建设部网站 审查系统天津网站seo设计
  • 网站建设兼容移动端企业推广策划公司
  • 做特卖网站有哪些vi设计公司
  • b2b的电子商务网站大全做一个简单网页
  • 广州新公司网站建设网址提交入口
  • 大数据营销的概念百度搜索引擎优化怎么做
  • 淘宝详情页做的比较好的网站seo81
  • 网站设计公司哪家比较好torrentkitty磁力猫引擎
  • 网站怎么做sem优化百度站长收录