博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
leetCode(51):Valid Palindrome
阅读量:7172 次
发布时间:2019-06-29

本文共 1246 字,大约阅读时间需要 4 分钟。

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

For example,

"A man, a plan, a canal: Panama" is a palindrome.
"race a car" is not a palindrome.

Note:

Have you consider that the string might be empty? This is a good question to ask during an interview.

For the purpose of this problem, we define empty string as valid palindrome.

//用两个指针实现。前提是要忽略其它符号

class Solution {public:    bool isPalindrome(string s) {        if(s.empty())            return true;        int i=0;        int j=s.size()-1;        for(;i
='a' && s[i]<='z') || (s[i]>='A' && s[i]<='Z') || (s[i]>='0' && s[i]<='9')) {//找到第一个为字符或数字的字符 for(;j>i;--j) {//j前移 if((s[j]>='a' && s[j]<='z') || (s[j]>='A' && s[j]<='Z') || (s[j]>='0' && s[j]<='9')) {//找到第一个为字符或数字的字符 if(s[i]==s[j] || s[i]+'A'-'a'==s[j] || s[i]+'a'-'A'==s[j]) {//找到后时行推断 j--;//前进一步 break; } else return false; } } } } return true; }};

转载地址:http://hsbzm.baihongyu.com/

你可能感兴趣的文章
OSSIM系统中Sensor的设置
查看>>
SCVMM2012部署之三:安装VMM自助服务门户
查看>>
支持多核smp squid3.2 缓存反向代理【ok】~
查看>>
一个Web页面的问题分析
查看>>
草根创业回忆录一: 踏出了第一步的时候...
查看>>
情景会话:请对产品提提意见好吗?
查看>>
Android应用程序组件Content Provider在应用程序之间共享数据的原理分析(5)
查看>>
使用组策略配置域中计算机注册表安全
查看>>
使用spotlight on unix监控linux主机
查看>>
【习惯的力量】之五让拖延见鬼去吧
查看>>
Twisted入门教程(13)
查看>>
Java通过FTP服务器上传下载文件的解决方案
查看>>
SVN “不能打开文件“.svn/lock” 权限不够”精解
查看>>
【电信增值业务学习笔记】9基于智能网的增值业务实现技术和应用
查看>>
你的python内部是用什么编码表示unicode的?
查看>>
javascript之数组
查看>>
jquery - How can I recurse up a DOM tree? - Stack Overflow
查看>>
java环境变量配置
查看>>
世界末日?
查看>>
深度解读 - Windows 7核心图形架构细致分析(转贴)
查看>>