125. Valid Palindrome【easy】

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) {
int start = , end = s.length() - ;
while (start <= end) {
if (!isalnum(s[start])) {
start++;
} else if (!isalnum(s[end])) {
end--;
} else {
if (tolower(s[start++]) != tolower(s[end--])) {
return false;
}
}
}
return true;
}
};

125. Valid Palindrome【easy】的更多相关文章

  1. 680. Valid Palindrome II【easy】

    680. Valid Palindrome II[easy] Given a non-empty string s, you may delete at most one character. Jud ...

  2. 234. Palindrome Linked List【easy】

    234. Palindrome Linked List[easy] Given a singly linked list, determine if it is a palindrome. Follo ...

  3. 661. Image Smoother【easy】

    661. Image Smoother[easy] Given a 2D integer matrix M representing the gray scale of an image, you n ...

  4. 657. Judge Route Circle【easy】

    657. Judge Route Circle[easy] Initially, there is a Robot at position (0, 0). Given a sequence of it ...

  5. 2. Trailing Zeros【easy】

    2. Trailing Zeros[easy] Write an algorithm which computes the number of trailing zeros in n factoria ...

  6. 170. Two Sum III - Data structure design【easy】

    170. Two Sum III - Data structure design[easy] Design and implement a TwoSum class. It should suppor ...

  7. 160. Intersection of Two Linked Lists【easy】

    160. Intersection of Two Linked Lists[easy] Write a program to find the node at which the intersecti ...

  8. 206. Reverse Linked List【easy】

    206. Reverse Linked List[easy] Reverse a singly linked list. Hint: A linked list can be reversed eit ...

  9. 203. Remove Linked List Elements【easy】

    203. Remove Linked List Elements[easy] Remove all elements from a linked list of integers that have ...

随机推荐

  1. 【动态规划】【记忆化搜索】1017 乘积最大 2000年NOIP全国联赛普及组NOIP全国联赛提高组

    跟CODEVS 3415没有什么区别,也不用高精度. http://www.cnblogs.com/autsky-jadek/p/4055184.html #include<cstdio> ...

  2. 【KM】POJ2195/HDU1533-Going home

    //最近没什么时间quq据说长得帅的人都在切八中,然而长得丑的人只能水水裸题 [题目大意] 给出一张地图及人和房屋的位置,求出每个人回到不同房屋所具有的最小代价和. [思路] 最小权匹配,先O(n^2 ...

  3. 【OpenJudge9267】【递推】核电站

    核电站 总时间限制: 5000ms 单个测试点时间限制: 1000ms 内存限制: 131072kB [描述] 一个核电站有N个放核物质的坑,坑排列在一条直线上.如果连续M个坑中放入核物质,则会发生爆 ...

  4. jvm内存参数配置

    qunar国内旗舰店master  (4核 8G) qunar国内旗舰店hub(4核 8G) qunar国内旗舰店provider(4核 8G)

  5. PHP反射(ReflectionClass、ReflectionMethod)在ThinkPHP框架的控制器调度模块中的应用

    ThinkPHP框架的控制器模块是如何实现 前控制器.后控制器,及如何执行带参数的方法? PHP系统自带的 ReflectionClass.ReflectionMethod 类,可以反射用户自定义类的 ...

  6. Step by Step 使用HTML5开发一个星际大战游戏(2)

    HTML5 Canvas Game: 玩家飞船  本系列博文翻译自以下文章 http://blog.sklambert.com/html5-canvas-game-the-player-ship/ L ...

  7. 【InteillJ IDEA】Git的安装+同步项目到GitHub上

    需要的工具: 1.InteillJ IDEA 2.Git 3.GitHub帐号 步骤: 1.下载Git 下载地址:https://git-scm.com/downloads 安装完成后 勾选Launc ...

  8. app crash率的标准

    手Q定义是: android:   发布目标是低于1% ios:  0.8%以下

  9. 一个简单的JS函数,用于判断文本是否数字

    /****************************************************** 判断是否是数字(整数,小数均可,不包括负数)* 2014年10月10日22:38:19* ...

  10. Python 提取Twitter tweets中的元素(包括text, screen names, hashtags)

    CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-1 @author: guaguastd @name: ex ...