Valid Palindrome

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
 
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.

Challenge

O(n) time without extra memory.

深刻体会到了英文的用处。。。题目的中文翻译真是误导人。

 public class Solution {
/**
* @param s A string
* @return Whether the string is a valid palindrome
*/
public boolean isPalindrome(String s) {
char[] cs = s.toCharArray();
int i = 0;
int j = cs.length - 1; while(i<j) {
while(i<j && !Character.isDigit(cs[i]) && !Character.isLetter(cs[i])) i++;
while(i<j && !Character.isDigit(cs[j]) && !Character.isLetter(cs[j])) j--;
if(i >= j) break;
String ss = cs[i] + "";
String ss1 = cs[j] + "";
if(!ss.equalsIgnoreCase(ss1))
return false; i++;
j--;
}
return true;
}
}

Valid Palindrome(LintCode)的更多相关文章

  1. LeetCode 之 Valid Palindrome(字符串)

    [问题描写叙述] Given a string, determine if it is a palindrome, considering only alphanumeric characters a ...

  2. leetcode 之Valid Palindrome(26)

    现在开始进入字符串系列. 判断回文串的.首尾各定义一个指针,然后相比较.难点在于如何提出非字母数字的字符. bool isValidPalind(string s) { //转为小写,注意这个函数的用 ...

  3. 【LeetCode】- Valid Palindrome(右回文)

    [ 问题: ] Given a string, determine if it is a palindrome, considering only alphanumeric characters an ...

  4. leetcode题解:Valid Palindrome(判断回文)

    题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ig ...

  5. LeetCode 125 Valid Palindrome(有效回文)(*)

    翻译 给定一个字符串.确定它是否是回文的,仅仅考虑当中的数字和字符并忽略其它. 比如. "A man, a plan, a canal: Panama" 是回文的. "r ...

  6. LeetCode OJ:Valid Palindrome(验证回文)

    Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric char ...

  7. 415. Valid Palindrome【LintCode java】

    Description Given a string, determine if it is a palindrome, considering only alphanumeric character ...

  8. LeetCode:36. Valid Sudoku(Medium)

    1. 原题链接 https://leetcode.com/problems/valid-sudoku/description/ 2. 题目要求 给定一个 9✖️9 的数独,判断该数独是否合法 数独用字 ...

  9. LeetCode算法题-Valid Palindrome(Java实现)

    这是悦乐书的第174次更新,第176篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第33题(顺位题号是125).给定一个字符串,确定它是否是回文,只考虑字母数字字符并忽略 ...

随机推荐

  1. Transformation(线段树+HDU4578+多种操作+鬼畜的代码)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4578 题目: 题意:n个数初始值为0,进行四种操作:1.将区间内的数字加c:2.将区间内的数字乘c:3 ...

  2. canvas利用formdata上传到服务器

    1.首先绘制canvas图片 <canvas id="myCanvas" width="100" height="100" style ...

  3. windows下 nginx安装 使用

    介绍 Nginx (engine x) 是一个高性能的HTTP和反向代理服务器. 反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络 ...

  4. Spring Boot提供的特性

    一.导览 本文主要按以下模块介绍spring Boot(1.3.6.RELEASE)提供的特性. SpringApplication类 外部化配置 Profiles 日志 开发WEB应用 Securi ...

  5. js中的indexOf

    1.概述 indexOf大小写敏感,其中的O要大写 2.对于字符串而言 indexOf返回字符串第一次出现的位置,若没有出现返回-1 var str = "hello world" ...

  6. CentOS7安装MySQL5.7以及修改密码

    CentOS7安装mysql [root@bd005 ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch. ...

  7. 从零开始PHP攻略(001)——Bob的汽车零部件商店

    1.创建订单表单 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...

  8. Python数据处理实战

    一.运行环境 1.python版本 2.7.13 博客代码均是这个版本2.系统环境:win7 64位系统 二.需求 对杂乱文本数据进行处理 部分数据截图如下,第一个字段是原字段,后面3个是清洗出的字段 ...

  9. Python爬虫之百度API调用

    调用百度API获取经纬度信息. import requests import json address = input('请输入地点:') par = {'address': address, 'ke ...

  10. DXEditingRow的错误原因

    原因之一:例如commbox理由id这一列但是数据库表中没有的话就会报这个错误