Valid Palindrome
来源:互联网 发布:asp.net php 编辑:程序博客网 时间:2024/04/27 08:58
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) { // Start typing your C/C++ solution below // DO NOT write int main() function if(s.length() == 0) return true; int i = 0,j = s.length() - 1; while(i < j) { while(!isalnum(s[i]) && i < j ) i++; if(i==j) return true; while(!isalnum(s[j])) j--; if(i>=j) return true; if(tolower(s[i++]) != tolower(s[j--])) return false; } return true; }};
52 milli secs
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- valid palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- javascript添加或删除DOM标签
- java 文件操作 Io
- 未能加载文件或程序集“vjslib, Version=2.0.0.0, Culture=neutral
- hdoj_1421搬寝室
- java集合之ArrayList
- Valid Palindrome
- 二叉树的非递归前序,中序,后序遍历算法
- SSIS 尝试运行官方的示例 DataCleaning.sln项目0xC0202009 at DataCleaning, Connection manager "LocalHost.Adventure
- 检测编码
- c语言实现字符串分割
- 使用Aspose.Pdf在PDF文件中添加表格字段
- 《鸟哥的linux私房菜 基础篇》第三章学习笔记
- xbmc视频插件开发入门教程
- IE下getJSON不工作的解决办法