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. 2015必须推荐的Android框架,猿必读系列!

    一.Guava Google 的基于java1.6的类库集合的扩展项目,包括collections, caching, primitives support, concurrency librarie ...

  2. android 让图片充满整个屏幕

    方法1: <ImageView android:id="@+id/imageView1" android:layout_width="fill_parent&quo ...

  3. SQL语言的组成

    在正式学习SQL语言之前,首先让我们对SQL语言有一个基本认识,介绍一下SQL语言的 组成: 1.一个SQL数据库是表(Table)的集合,它由一个或多个SQL模式定义. 2.一个SQL表由行集构成, ...

  4. poj3358:欧拉定理

    又是一道用欧拉定理解的题..嗯,关键还是要建好方程,注意一些化简技巧 题目大意: 给定一个由 p / q 生成的循环小数,求此循环小数在二进制表示下的最小循环节以及不是循环节的前缀 思路: 小数化为二 ...

  5. PHP页面静态化(转)

    在很多地方都看到有PHP整站静态化的东东,怪唬人的..其实,你会静态化一个页面,那么别说整站了,想静态化多少都可以.所以关键是,首先要知道怎么静态化一个页面,了解静态化的原理是关键.. 这里就说下我个 ...

  6. c指针点滴1

    #include <stdio.h> #include <stdlib.h> void main() { ; int *p = &num;//&num是一个地址 ...

  7. NetAnalyzer笔记 之 二. 简单的协议分析

    [创建时间:2015-08-27 22:15:17] NetAnalyzer下载地址 上篇我们回顾完了NetAnalyzer一些可有可无的历史,在本篇,我决定先不对NetAnalyzer做介绍,而是先 ...

  8. Android开发小问题——java使用

    2013-09-25 导语:离上次写博客有点久了,这次写两个开发中解决的问题吧. 正文: 1.ArrayList<E>使用remove问题: 2.字符串映射到函数运行方法: ==== 1. ...

  9. VCS仿真生成vpd文件(verilog)

    VCS仿真生成vpd文件(verilog) 一.环境与文件 Linux平台  csh环境 VCS 64bit 代码文件请参考<一个简单的Verilog计数器模型> 二.开始仿真 1.com ...

  10. Fedora安装VirtualBox时出现错误Kernel driver not installed (rc=-1908)的解决办法

    新建虚拟机后启动时出现如下错误: Kernel driver not installed (rc=-1908) The VirtualBox Linux kernel driver (vboxdrv) ...