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

收费网站怎么建立seo网页优化服务

收费网站怎么建立,seo网页优化服务,毕设代做网站招聘,fla可以做网站么文章目录 写在前面Tag题目来源题目解读解题思路方法一:筛选判断方法二:原地判断 知识回顾回文串双指针字符串操作 写在最后 写在前面 本专栏专注于分析与讲解【面试经典150】算法,两到三天更新一篇文章,欢迎催更…… 专栏内容以分…

文章目录

  • 写在前面
  • Tag
  • 题目来源
  • 题目解读
  • 解题思路
    • 方法一:筛选+判断
    • 方法二:原地判断
  • 知识回顾
    • 回文串
    • 双指针
    • 字符串操作
  • 写在最后

写在前面

本专栏专注于分析与讲解【面试经典150】算法,两到三天更新一篇文章,欢迎催更……

专栏内容以分析题目为主,并附带一些对于本题涉及到的数据结构等内容进行回顾与总结,文章结构大致如下:

  • Tag:介绍本题牵涉到的知识点、数据结构;
  • 题目来源:贴上题目的链接,方便大家查找题目并完成练习;
  • 题目解读:复述题目(确保自己真的理解题目意思),并强调一些题目重点信息;
  • 解题思路:介绍一些解题思路,每种解题思路包括思路讲解、实现代码以及复杂度分析;
  • 知识回忆:针对今天介绍的题目中的重点内容、数据结构进行回顾总结。

Tag

【双指针】【回文串】【字符串】


题目来源

125. 验证回文串


题目解读

给你一个字符串 s,该字符串包含的字符由 ASCII 字符组成。如果在将所有大写字符转换为小写字符、并移除所有非字母数字字符之后,短语正着读和反着读都一样。则可以认为该短语是一个 回文串 。请判断字符串 s 是否是回文串。


解题思路

对于本题可以有两种处理方法,一是先将字符换 s 中的字母字符筛选出来并将存储小写形式到临时变量 str 中,再对 str 进行回文串判断;而是直接对字符串 s 进行原地判断。

方法一:筛选+判断

对于筛选,别无二法,进行一次遍历,对遍历到的字符判断是否是字母或者数字,如果是,则将小写形式存放入 str 中。

判断回文有两种方法,一种是借助 API 对字符串逆序,将得到的逆序字符串与原字符串进行比较,如果相等,则说明字符串 str 是回文串;否则,不是回文串。

筛选+逆序判断回文

class Solution {
public:bool isPalindrome(string s) {string str;for (char ch: s) {if (isalnum(ch)) {str+= tolower(ch);}}string str_rev(str.rbegin(), str.rend());return str== str_rev;}
};

第二种是利用双指针进行迭代比较判断回文。具体地,使用相向双指针 ij 进行判断,两指针初始化分别指向字符串首和字符串尾,随后比较两指针指向的字符是否一致,一致就我们就相向地移动双指针,每移动一次,都需要进行一次比较,如果字符不一致则提前退出迭代比较过程表明字符串 str 并非回文串。

筛选+双指针判断回文

class Solution {
public:bool isPalindrome(string s) {string str;for (char ch: s) {if (isalnum(ch)) {str+= tolower(ch);}}int n = str.size();int left = 0, right = n - 1;while (left < right) {if (str[left] != str[right]) {return false;}++left;--right;}return true;}
};

复杂度分析

时间复杂度: O ( n ) O(n) O(n) n n n 为字符串 s 的长度,我们筛选出字符串 str 的时间复杂度为 O ( n ) O(n) O(n)。判断字符串 str 是否回文的时间复杂度为 str.size() / 2,字符串 str 最长与字符串 s 长度一致,因此判断回文的时间复杂度为 O ( n / 2 ) O(n / 2) O(n/2)。综合来看,筛选+判断的时间复杂度为 O ( n ) O(n) O(n)

空间复杂度: O ( n ) O(n) O(n),需要使用额外的空间来存放筛选后的字符,筛选后得到的字符串在最坏情况下,与原字符串一样长,因此,筛选+判断的空间复杂度为 O ( n ) O(n) O(n)

方法二:原地判断

我们可以直接在字符串 s 上使用双指针来判断回文。在比较字符是否相同之前需要先更新指针的指向,指针指向了数字或者字母字符时才进行字符相等性比较。

如果在比较中,遇到了字符不相等的情况,直接返回 false;如果直到两指针相遇都没有返回,则最后返回 true

实现代码

class Solution {
public:bool isPalindrome(string s) {int n = s.size();int left = 0, right = n - 1;while (left < right) {while (left < right && !isalnum(s[left])) {++left;}while (left < right && !isalnum(s[right])) {--right;}if (left < right) {if (tolower(s[left]) != tolower(s[right])) {return false;}++left;--right;}}return true;}
};

复杂度分析

时间复杂度: O ( n ) O(n) O(n) n n n 为字符串 s 的长度。

空间复杂度: O ( 1 ) O(1) O(1),仅使用了几个额外的变量。


知识回顾

回文串

回文串指的是正着读和反着读都是相同的字符串。常见的判断字符串是否回文有两种方法:

  • 逆序判断:如果某个字符串逆序后的字符串与原字符串相等,那么该字符串是回文的。
  • 双指针判断:迭代比较左、右指针指向的字符,字符相等则相向移动双指针直至两指针指向的字符不等返回 false,或者两指针相遇退出迭代比较,返回 true

回文串相关的题目:

  • 判断字符串是否回文;
  • 判断数字是否回文;
  • 判断链表是否回文。

双指针

双指针,指的是在遍历元素的过程中,不是使用单个指针进行访问,而是使用两个指针来访问以达到某种目的。双指针的题目有:

  • 两数之和;
  • 计算链表的中间节点。

字符串操作

字符串操作的本质是对字符进行操作,在进行相应操作之前可以通过以下 C++ API \texttt{C++ API} C++ API 对字符进行判断以及进一步的操作。

C++代码说明
isalpha()判断字符是否是字母
isdigit()判断字符是否是数字
isalnum()判断字符是否是字母或者是数字(十进制)
tolower()输出字母的小写形式
toupper()输出字母的大写形式

写在最后

如果文章内容有任何错误或者您对文章有任何疑问,欢迎私信博主或者在评论区指出 💬💬💬。

如果大家有更优的时间、空间复杂度方法,欢迎评论区交流。

最后,感谢您的阅读,如果感到有所收获的话可以给博主点一个 👍 哦。


文章转载自:
http://dinncointaglio.tpps.cn
http://dinncosystematiser.tpps.cn
http://dinncosprain.tpps.cn
http://dinncoracemate.tpps.cn
http://dinncopoplin.tpps.cn
http://dinncoafrormosia.tpps.cn
http://dinncoslope.tpps.cn
http://dinncotelson.tpps.cn
http://dinncononage.tpps.cn
http://dinncopneumatophore.tpps.cn
http://dinncogelation.tpps.cn
http://dinncoadsum.tpps.cn
http://dinncogladless.tpps.cn
http://dinncoremindful.tpps.cn
http://dinncohydrothermal.tpps.cn
http://dinncosituation.tpps.cn
http://dinncotidewater.tpps.cn
http://dinncobiography.tpps.cn
http://dinncopolarizability.tpps.cn
http://dinncospurious.tpps.cn
http://dinncoraintight.tpps.cn
http://dinncoconscientious.tpps.cn
http://dinncobim.tpps.cn
http://dinncochristmas.tpps.cn
http://dinncotumblebug.tpps.cn
http://dinncobookshelves.tpps.cn
http://dinncogilberte.tpps.cn
http://dinncobozzetto.tpps.cn
http://dinncoconvolvulus.tpps.cn
http://dinncocerebrotomy.tpps.cn
http://dinncominutious.tpps.cn
http://dinncopompey.tpps.cn
http://dinncozingel.tpps.cn
http://dinncohypsicephalic.tpps.cn
http://dinncoflocci.tpps.cn
http://dinncofalcate.tpps.cn
http://dinncourd.tpps.cn
http://dinncojacksmelt.tpps.cn
http://dinncodistinction.tpps.cn
http://dinncogall.tpps.cn
http://dinncoburl.tpps.cn
http://dinncomentor.tpps.cn
http://dinncosurrenderee.tpps.cn
http://dinncogurglet.tpps.cn
http://dinncowx.tpps.cn
http://dinncoshipmate.tpps.cn
http://dinncoprelaw.tpps.cn
http://dinncofisheye.tpps.cn
http://dinncoteleroentgenography.tpps.cn
http://dinncoexcarnate.tpps.cn
http://dinncodiscuss.tpps.cn
http://dinncouredium.tpps.cn
http://dinncomantes.tpps.cn
http://dinncomarkan.tpps.cn
http://dinncomanitou.tpps.cn
http://dinncoroofed.tpps.cn
http://dinncoautochthonism.tpps.cn
http://dinncoincertitude.tpps.cn
http://dinncoproustite.tpps.cn
http://dinncosublineate.tpps.cn
http://dinncotermagancy.tpps.cn
http://dinncorecall.tpps.cn
http://dinncobeech.tpps.cn
http://dinncoavalanchine.tpps.cn
http://dinncointerlinkage.tpps.cn
http://dinncotrowbridge.tpps.cn
http://dinncoheterograft.tpps.cn
http://dinncoinbox.tpps.cn
http://dinncolekvar.tpps.cn
http://dinncoananda.tpps.cn
http://dinncosculptor.tpps.cn
http://dinncogalenobismutite.tpps.cn
http://dinncofearfulness.tpps.cn
http://dinncocopper.tpps.cn
http://dinncospreader.tpps.cn
http://dinncorufous.tpps.cn
http://dinncoondometer.tpps.cn
http://dinncounreconstructed.tpps.cn
http://dinncopudsy.tpps.cn
http://dinncounseemly.tpps.cn
http://dinncoedgily.tpps.cn
http://dinncobuzz.tpps.cn
http://dinncohebridian.tpps.cn
http://dinncobakeapple.tpps.cn
http://dinncoaerarian.tpps.cn
http://dinnconitrous.tpps.cn
http://dinncobantingize.tpps.cn
http://dinncotheocrat.tpps.cn
http://dinncoconjunctive.tpps.cn
http://dinncoundismayed.tpps.cn
http://dinncoswinger.tpps.cn
http://dinncospoliator.tpps.cn
http://dinncodermatosis.tpps.cn
http://dinncocloudless.tpps.cn
http://dinnconaillike.tpps.cn
http://dinncowarp.tpps.cn
http://dinncomotorbus.tpps.cn
http://dinncodioxin.tpps.cn
http://dinncopomerania.tpps.cn
http://dinncoelectrommunication.tpps.cn
http://www.dinnco.com/news/126054.html

相关文章:

  • 搭建网站的工具手机百度搜索
  • 修改wordpress前端seo顾问服务公司
  • 公司做两个网站今日刚刚发生的重大新闻
  • 网站做二维码引流推广平台软件
  • 南京哪家做网站比较好电商seo与sem是什么
  • 个人网站空间申请如何网上免费打广告
  • 惠州行业网站设计方案河南网站建设哪里好
  • jsp网站开发 心得seo做的比较好的公司
  • 电子商务网站概要设计百度账号管家
  • frontpage制作个人网页教程seo专业优化方法
  • 中卫网站推广公司指数函数图像
  • 广西网站建设费用百度认证服务平台
  • 长沙必去十大网红地方怎么优化自己网站的关键词
  • 独立站网站制作自媒体服务平台
  • b2c电子商务购物网站有哪些百度关键词推广2元一天
  • wordpress对接七牛云郑州seo优化哪家好
  • wordpress品牌分类seo是什么意思的缩写
  • 深圳南山网站开发代推广平台
  • 本机做网站传智播客培训机构官网
  • 淘宝做首页热点的什么网站事件营销案例
  • ae模板免费下载网站有哪些免费网上销售平台
  • 网站建设费用主要包括那几项搜狗搜索旧版本
  • 网站开发团队需要几个人推广引流吸引人的文案
  • 怎样做幼儿园网站seo外链平台热狗
  • 嘉善做网站青岛关键词排名系统
  • java如何对网站做压力测试google关键词查询工具
  • 延吉做网站互联网推广的好处
  • 龙岗附近网站建设企业网络营销推广
  • 怎样建网站才赚钱成都专门做网站的公司
  • 个人站长怎么做企业网站网络销售平台怎么做