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. Codeforces 573B Bear and Blocks

    http://codeforces.com/problemset/problem/573/B  题目大意: 给出n个连续塔,每个塔有高度hi,每次取走最外层的块,问需要多少次操作能够拿光所有的块. 思 ...

  2. webservice的几个简单概念

    1.什么是JAX-WS? http://baike.baidu.com/view/1865210.htm?fr=aladdin 2.什么是JAX-RPC? http://baike.baidu.com ...

  3. [转]Ubuntu Tweak 0.8.7 发布:支持 Ubuntu 14.04

    原文网址:http://www.oschina.net/news/51054/ubuntu-tweak-0-8-7 这是我开发 Ubuntu Tweak 七年以来第一次没在 Ubuntu 正式发布之前 ...

  4. SDN,NFV

    CAPEX,capital expenditures  投资成本OPEX,Operating Expense 运营费用space & power consumption 图解NFV与SDN关系

  5. java 获取系统变量(环境变量和设置变量)

    前言 环境变量这个概念不陌生, 就是操作系统的环境变量. 系统变量就是java本身维护的变量. 通过 System.getProperty 的方式获取. 对于不同的操作系统来说, 环境变量的处理可能会 ...

  6. [原创作品] javascript 实现的web分页器原理

    很久没有写博客了,因为最近忙于一些杂七杂八的事情.不过,互联网的价值在于信息共享,因为共享,所以互联网才能飞快发展.博主建了一个技术共享qq群:164858883,因为目前人数还比较少,活跃度还不是很 ...

  7. java自定义随机数(实例)

    import java.util.Random; /** * * @author mengzw * @since 3.0 2014-5-22 */ public class RandomTest { ...

  8. CSS3 div水平、垂直居中,IE9以上、Firefox、Chrome均正常

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  9. MySQL server version for the right syntax to use near &#39;type=InnoDB&#39; at line 1

    转载请注明出处:http://blog.csdn.net/bettarwang/article/details/40180271 在执行一个Hibernate的演示样例时,配置了<propert ...

  10. 算法导论——lec 11 动态规划及应用

    和分治法一样,动态规划也是通过组合子问题的解而解决整个问题的.分治法是指将问题划分为一个一个独立的子问题,递归地求解各个子问题然后合并子问题的解而得到原问题的解.与此不同,动态规划适用于子问题不是相互 ...