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 check(char test, char & c)
{
if(test >= 'a' && test <= 'z')
{
c = test;
return true;
}else if(test >= 'A' && test <= 'Z'){ c = test - 'A' + 'a';
return true;
}else if (test >= '' && test <= ''){ c = test;
return true;
}
return false;
}
bool isPalindrome(string s) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int j = s.length();
if(j-- == ) return true;
int i = ; char head,tail;
while(i<j){
while(i<j){
if(check(s[i],head)) break;
i++;
}
if(i>=j) return true; while(i<j){
if(check(s[j], tail)) break;
j--;
}
if(i>=j) return true;
if(head != tail ) return false;
i++;j--;
}
return true ;
}
};

LeetCode_Valid Palindrome的更多相关文章

  1. 【leeetcode】125-Valid Palindrome

    problem 125. Valid Palindrome 参考 1. Leetcode_Valid Palindrome; 完

  2. PALIN - The Next Palindrome 对称的数

    A positive integer is called a palindrome if its representation in the decimal system is the same wh ...

  3. [LeetCode] Longest Palindrome 最长回文串

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

  4. [LeetCode] Palindrome Pairs 回文对

    Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list, so that t ...

  5. [LeetCode] Palindrome Permutation II 回文全排列之二

    Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...

  6. [LeetCode] Palindrome Permutation 回文全排列

    Given a string, determine if a permutation of the string could form a palindrome. For example," ...

  7. [LeetCode] Palindrome Linked List 回文链表

    Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time ...

  8. [LeetCode] Shortest Palindrome 最短回文串

    Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...

  9. [LeetCode] Palindrome Partitioning II 拆分回文串之二

    Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...

随机推荐

  1. Activity切换效果(overridePendingTransition)

    在Android开发过程中,经常会碰到Activity之间的切换效果的问题,下面介绍一下如何实现左右滑动的切换效果,首先了解一下Activity切换的实现,从Android2.0开始在Activity ...

  2. How to install phpmyadmin on centos 6

    Phpmyadmin :   Phpmyadmin is a free tool used to administrate MySQL . Phpmyadmin supports all major ...

  3. Android 使用HorizontalScrollView 实现Gallery效果

    Gallery(画廊)是一个锁定中心条目并且拥有水平滚动列表的视图,一般用来浏览图片,并且可以响应事件显示信息:Gallery还可以和ImageSwitcher组件结合使用来实现一个通过缩略图来浏览图 ...

  4. 浅谈单片机、ARM和DSP的异同

    犹记得当年读书的时候,老师说单片机.ARM.DSP有互通之处,都是CPU,但听老师讲都听不懂. 我该如何理解他们,并找出他们的异同呢?我们来看看行内人的看法: ICer,从事ARM CPU的SOC设计 ...

  5. .net中除去IList中的多余项

    IList<ActionInfo> tempList = new List<ActionInfo>(); IList<ActionInfo> tempActionL ...

  6. 以Crypto++实现RSA加解密二进制数据

    网上一大片讲怎么加解密字符串的,找了大半天也没找到讲加解密二进制数据的,于是自己研究了下,分享给大家. 加解密函数: #include <rsa.h> #include <randp ...

  7. hdu4623:crime 数学优化dp

    鞍山热身赛的题,也是去年多校原题 题目大意: 求n个数的排列中满足相邻两个数互质的排列的数量并取模 当时的思路就是状压dp.. dp[i][state]  state用二进制记录某个数是否被取走,i ...

  8. 小米路由器mini搭建个人静态网站的方法

    小米路由和小米路由mini从本质上来说差距就在1T的硬盘上,其它并没有明显差别,但是功能却差很多,例如:小米路由有自带的LAMP模式,而小米路由mini则没有,换句话说,其实这个功能是被阉割了,仔细研 ...

  9. Ruby中,类方法和实例方法的一个有趣的例子

    最初的代码如下: class Object def abc p "instance abc" end def self.abc p "class abc" en ...

  10. HDU1285——确定比赛名次

    Problem Description 有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委 ...