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. 奇偶排序Odd-even sort

    又一个比较性质的排序,基本思路是奇数列排一趟序,偶数列排一趟序,再奇数排,再偶数排,直到全部有序 举例吧, 待排数组[6 2 4 1 5 9] 第一次比较奇数列,奇数列与它的邻居偶数列比较,如6和2比 ...

  2. Intel MKL(Math Kernel Library)

    1.Intel MKL简介 Intel数学核心函数库(MKL)是一套高度优化.线程安全的数学例程.函数,面向高性能的工程.科学与财务应用.英特尔 MKL 的集群版本包括 ScaLAPACK 与分布式内 ...

  3. Java多线程学习(一)Java多线程入门

    转载请备注地址:https://blog.csdn.net/qq_34337272/article/details/79640870 系列文章传送门: Java多线程学习(一)Java多线程入门 Ja ...

  4. socket编程中write、read和send、recv之间的区别~转载

    socket编程中write.read和send.recv之间的区别   http://blog.csdn.net/petershina/article/details/7946615 一旦,我们建立 ...

  5. 【目录】Python模块学习系列

    目录:Python模块学习笔记 1.Python模块学习 - Paramiko  - 主机管理 2.Python模块学习 - Fileinput - 读取文件 3.Python模块学习 - Confi ...

  6. linux网络编程之IO函数

    Linux操作系统中的IO函数主要有read(),write(),recv(),send(),recvmsg(),sendmsg(),readv(),writev(). 接收数据的recv()函数 # ...

  7. Linux 入门记录:三、Linux 文件基本操作管理

    一.复制文件.目录 使用 cp 命令复制文件或目录: $ cp 源文件(夹)目标文件(夹) 常用参数: -r 递归复制整个目录树 -v 显示复制过程的详细信息 二.移动.重命名文件或目录 通过 mv  ...

  8. Deep Learning基础--26种神经网络激活函数可视化

    在神经网络中,激活函数决定来自给定输入集的节点的输出,其中非线性激活函数允许网络复制复杂的非线性行为.正如绝大多数神经网络借助某种形式的梯度下降进行优化,激活函数需要是可微分(或者至少是几乎完全可微分 ...

  9. [hadoop][会装]HBase集群安装--基于hadoop ha模式

    可以参考部署HBase系统(分布式部署) 和基于无HA模式的hadoop下部署相比,主要是修改hbase-site .xml文件,修改如下参数即可: <property> <name ...

  10. MyBatis 模糊查询 防止Sql注入

    #{xxx},使用的是PreparedStatement,会有类型转换,所以比较安全: ${xxx},使用字符串拼接,可以SQL注入: like查询不小心会有漏洞,正确写法如下:   Mysql:   ...