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

Note: For the purpose of this problem, we define empty string as valid palindrome.

Example 1:

Input: "A man, a plan, a canal: Panama"
Output: true

题目

判断回文串,只检查字母,不分大小写。

思路

双指针

代码

 class Solution {
public boolean isPalindrome(String s) {
s = s.toLowerCase();
int left = 0;
int right = s.length()-1;
while(left < right){
// check white spaces
if(!Character.isLetterOrDigit(s.charAt(left))) left++;
// check white spaces
else if(!Character.isLetterOrDigit(s.charAt(right))) right--;
else if(s.charAt(left) != (s.charAt(right))) return false;
else {
left++ ;
right--;
}
}
return true;
}
}

[leetcode]125. Valid Palindrome判断回文串的更多相关文章

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

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

  2. lintcode :Valid Palindrome 有效回文串

    题目: 有效回文串 给定一个字符串,判断其是否为一个回文串.只包含字母和数字,忽略大小写. 样例 "A man, a plan, a canal: Panama" 是一个回文. & ...

  3. [LeetCode] 214. Shortest Palindrome 最短回文串

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

  4. LeetCode 125. Valid Palindorme (验证回文字符串)

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

  5. 125 Valid Palindrome 验证回文字符串

    给定一个字符串,确定它是否是回文,只考虑字母数字字符和忽略大小写.例如:"A man, a plan, a canal: Panama" 是回文字符串."race a c ...

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

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

  7. HDOJ/HDU 2163 Palindromes(判断回文串~)

    Problem Description Write a program to determine whether a word is a palindrome. A palindrome is a s ...

  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(125):验证回文串

    Easy! 题目描述: 给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写. 说明:本题中,我们将空字符串定义为有效的回文串. 示例 1: 输入: "A man, ...

随机推荐

  1. IP地址与子网掩码

    IP地址 众所周知,为了确保通信时能相互识别,在internet上的每台主机都必须有一个唯一的标识,即主机的IP地址.IP协议就是根据IP地址来实现信息传递的. IP地址由32位(4字节)二进制数组成 ...

  2. ie下 iframe在页面中显示白色背景 如何去掉的问题

    ie下:

  3. 【Codeforces】CF 165 E Compatible Numbers(状压dp)

    题目 传送门:QWQ 分析 很难想到方向,但有方向了就很easy了. 我们如何减少不必要的计算? 如果我们知道了$ 100111 $的相容的数,$ 100101 $的相容数和他是完全一样的. 我们就靠 ...

  4. 深入分析Java Web技术内幕 修订版 pdf

    百度网盘:http://pan.baidu.com/s/1slHCCw9

  5. python之列表操作

    1.列表的增操作(四种) append(object):append object to end,directly used on list insert(index,object):insert o ...

  6. vi规范

    pep8规范 # vi规范## , 后空一格# 函数和其他代码空两行

  7. vmware桥接模式无法上网

    环境:本机win10系统,ip地址固定,(估计存在vlan网络), 状况:vmware的nat模式可以上网,桥接模式不能上网, 解决办法:找网管把本机设置成dhcp模式,才行了

  8. 机器学习入门-混淆矩阵-准确度-召回率-F1score 1.itertools.product 2. confusion_matrix(test_y, pred_y)

    1. itertools.product  进行数据的多种组合 intertools.product(range(0, 1), range(0, 1))  组合的情况[0, 0], [0, 1], [ ...

  9. UI5-文档-2.5-开发混合Web容器

    开发混合Web容器 您可以将移动应用程序开发为混合应用程序,该混合应用程序由本机应用程序包装程序(例如PhoneGap)和HTML查看器组成,用于在用户界面上显示内容. 混合应用程序的优点是可以在应用 ...

  10. mysql case, if

    if语句: 用法和excel的if函数很像 if(expr1, value_if_expr1_is_true, value_if_expr1_is_false) select if(tag = 3, ...