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.

只考虑数字和字母,字母大小写都一样,判断是否是回文。重点是忽略非非字母和数字。比较简单。

 public class Solution {
public boolean isPalindrome(String s) { int low=0;
int high=s.length()-1;
String s1=s.toLowerCase();
while(low<high)
{ while(low<high)
{
char c=s1.charAt(low);
if((c>='a'&&c<='z')||(c>='0'&&c<='9'))
{
break;
}
else low++; } while(low<high)
{
char c=s1.charAt(high);
if((c>='a'&&c<='z')||(c>='0'&&c<='9'))
{
break;
}else high--; } if(s1.charAt(low)==s1.charAt(high))
{
low++;
high--;
}
else
{
return false;
} } return true; }
}

leecode 回文字符串加强版的更多相关文章

  1. leecode刷题(15)-- 验证回文字符串

    leecode刷题(15)-- 验证回文字符串 验证回文字符串 给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写. 说明:本题中,我们将空字符串定义为有效的回文串. 示例 ...

  2. [LeetCode] Valid Palindrome 验证回文字符串

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  3. 回文字符串的判断!关于strlen(char * str)函数

    #include <stdio.h> #include <string.h> int ishuiw(char * p); int main() { ;//true-false接 ...

  4. NYOJ_37.回文字符串 (附滚动数组)

    时间限制:3000 ms  |  内存限制:65535 KB 难度:4 描述 所谓回文字符串,就是一个字符串,从左到右读和从右到左读是完全一样的,比如"aba".当然,我们给你的问 ...

  5. 131. 132. Palindrome Partitioning *HARD* -- 分割回文字符串

    131. Palindrome Partitioning Given a string s, partition s such that every substring of the partitio ...

  6. leetcode:Longest Palindromic Substring(求最大的回文字符串)

    Question:Given a string S, find the longest palindromic substring in S. You may assume that the maxi ...

  7. 【又见LCS】NYOJ-37 回文字符串

    [题目链接] 回文字符串 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 所谓回文字符串,就是一个字符串,从左到右读和从右到左读是完全一样的,比如"aba& ...

  8. [NYOJ 37] 回文字符串

    回文字符串 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 所谓回文字符串,就是一个字符串,从左到右读和从右到左读是完全一样的,比如"aba".当 ...

  9. 最长回文字符串(manacher算法)

    偶然看见了人家的博客发现这么一个问题,研究了一下午, 才发现其中的奥妙.Stupid. 题目描述:      回文串就是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串. ...

随机推荐

  1. bzoj1260[CQOI2007]涂色paint

    思路:区间dp,用f[i][j]表示区间[i,j]的答案,然后转移即可. #include<iostream> #include<cstdio> #include<cst ...

  2. Peter Pan By: J. M. Barrie

    Audio book: (mp3+txt) http://www.booksshouldbefree.com/book/peter-pan-by-j-m-barrie

  3. 今天收到报警邮件,提示网站502 bad gateway,

    今天收到报警邮件,提示网站502 bad gateway, 输入网站url后果然无法打开: 登录服务器查看nginx进程正常: 查看fastcGI进程已经停止运行了: 问题找到后就该查找是什么原因产生 ...

  4. Fedora 21 安装QQ国际版

    首先安装依赖包 sudo yum install freetype.i686 libpng.i686 libgcc.i686 libXau.i686 点击下载wine-2012qq国际版 unzip ...

  5. [C#]Thread Safe Dictionary in .NET 2.0

    using System.Collections.Generic; using System.Threading; namespace CSharpUtilHelpV2 { /// <summa ...

  6. mac下Apache + MySql + PHP网站开发

    最近接了个小活,做一个使用PHP语言和MySql数据库的动态网站.之前做过类型的网站,是在windows系统下做的,开发环境使用的是 AppServ 的PHP开发套件.现在有了我的大MAC,所以找了M ...

  7. python实现雅虎拍卖后台自动回复卖家消息

    前些时间,公司让做一个自动回复卖家信息的程序,现在总结下(用python实现的) 1.登陆雅虎拍卖后台手动获取cookie文件 #coding=utf-8 import sqlite3 import ...

  8. linux重新增加硬盘容量

    1.先用df -h查看硬盘使用情况 2.fdisk -l查看分区情况 表示还没有挂载 3.fdisk /dev/vdb进行分区 4.mkfs.ext3 /dev/vdb进行格式化 5.mount /d ...

  9. sqlsever2008数据库的备份与还原

    本文数据库的名称为ProjectControl  public static SqlConnection conn = new SqlConnection("server=(local);u ...

  10. C#中指针使用总结

    C#为了类型安全,默认并不支持指针.但是也并不是说C#不支持指针,我们可以使用unsafe关键词,开启不安全代码(unsafe code)开发模式.在不安全模式下,我们可以直接操作内存,这样就可以使用 ...