题目描述

判断题目给出的字符串是不是回文,仅考虑字符串中的字母字符和数字字符,并且忽略大小写
例如:"A man, a plan, a canal: Panama"是回文
"race a car"不是回文
注意:
你有没有考虑过字符串可能为空?这是面试时应该提出的一个好问题。
针对这个问题,我们定义空字符串是回文


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.

示例1

输入

复制

"A man, a plan, a canal: Panama"

输出

复制

true
示例2

输入

复制

"race a car"

输出

class Solution {
public:
    /**
     *
     * @param s string字符串
     * @return bool布尔型
     */

bool isPalindrome(string s) {
        int i,j;
        for(i=0,j=s.length()-1;i<j;++i,--j){
            while(i<j && !isalnum(s[i])) ++i;
            while(i<j && !isalnum(s[j])) --j;
            if (i<j && tolower(s[i])!=tolower(s[j])) return false;
        }
        return true;
    }

};

最新文章

  1. 在Heroku部署时,无法加载 css,js,图片资源解决办法
  2. [Python]logging模块使用basicConfig后记录日志重复问题
  3. java 代码如何生成 chm
  4. linux/shell sort命令
  5. vs2013搭建团队版本控制 TFS、SVN
  6. hdu Hat&#39;s Tea
  7. 关于wkwebview
  8. jQuery系列 第四章 jQuery框架的选择器
  9. 和逛微博、刷朋友圈一样玩转 GitHub
  10. 【linux日常】 ACL权限管理
  11. Flutter - Migrate to AndroidX
  12. mysql安装5.7.20版本
  13. python学习 day13 迭代器,生成器,枚举对象
  14. 【九天教您南方cass 9.1】 03 编码法绘制地形图
  15. MySQL操作数据库--与MySQL零距离接触1-7
  16. linux动态追踪神器——Strace实例介绍【转】
  17. 《Erlang程序设计(第2版)》
  18. python基础学习1-函数相关
  19. javascript 内置类型
  20. Mysql 知识点总结

热门文章

  1. P6268 [SHOI2002]舞会
  2. 配置adpate的方式
  3. FY2E HDF格式数据处理绘图
  4. 物联网wifi模块
  5. 【二分】CF Round #587 (Div. 3)E2 Numerical Sequence (hard version)
  6. swoft生成控制器
  7. 服务器同一个tomcat部署2两个相同的项目
  8. Java Map转成xml标签字符串
  9. SQL SERVER调优常用方法 sql优化
  10. 用node.js给C#写一个数据表的实体类生成工具