Valid Palindrome(LintCode)
Valid Palindrome
"A man, a plan, a canal: Panama"
is a palindrome.
"race a car"
is not a palindrome.
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.
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)的更多相关文章
- LeetCode 之 Valid Palindrome(字符串)
[问题描写叙述] Given a string, determine if it is a palindrome, considering only alphanumeric characters a ...
- leetcode 之Valid Palindrome(26)
现在开始进入字符串系列. 判断回文串的.首尾各定义一个指针,然后相比较.难点在于如何提出非字母数字的字符. bool isValidPalind(string s) { //转为小写,注意这个函数的用 ...
- 【LeetCode】- Valid Palindrome(右回文)
[ 问题: ] Given a string, determine if it is a palindrome, considering only alphanumeric characters an ...
- leetcode题解:Valid Palindrome(判断回文)
题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ig ...
- LeetCode 125 Valid Palindrome(有效回文)(*)
翻译 给定一个字符串.确定它是否是回文的,仅仅考虑当中的数字和字符并忽略其它. 比如. "A man, a plan, a canal: Panama" 是回文的. "r ...
- LeetCode OJ:Valid Palindrome(验证回文)
Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric char ...
- 415. Valid Palindrome【LintCode java】
Description Given a string, determine if it is a palindrome, considering only alphanumeric character ...
- LeetCode:36. Valid Sudoku(Medium)
1. 原题链接 https://leetcode.com/problems/valid-sudoku/description/ 2. 题目要求 给定一个 9✖️9 的数独,判断该数独是否合法 数独用字 ...
- LeetCode算法题-Valid Palindrome(Java实现)
这是悦乐书的第174次更新,第176篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第33题(顺位题号是125).给定一个字符串,确定它是否是回文,只考虑字母数字字符并忽略 ...
随机推荐
- [USACO Mar08] 牛跑步
http://www.cogs.pro/cogs/problem/problem.php?pid=133 ★★★ 输入文件:cowjog.in 输出文件:cowjog.out 简单对比时间 ...
- POJ 3087 Shuffle'm Up DFS
link:http://poj.org/problem?id=3087 题意:给你两串字串(必定偶数长),按照扑克牌那样的洗法(每次从S2堆底中拿第一张,再从S1堆底拿一张放在上面),洗好后的一堆可以 ...
- Java反射中method.isBridge() 桥接方法
桥接方法是 JDK 1.5 引入泛型后,为了使Java的泛型方法生成的字节码和 1.5 版本前的字节码相兼容,由编译器自动生成的方法.我们可以通过Method.isBridge()方法来判断一个方法是 ...
- LTC 钱包部署
基础环境 系统: CentOS 7.x nodejs: v4.6.0 zeromq: 4.x 安装nodejs + zeromq 基础依赖 yum install -y gcc make gcc-c+ ...
- Spring boot 集成Dubbox(山东数漫江湖)
前言 因为工作原因,需要在项目中集成dubbo,所以去查询dubbo相关文档,发现dubbo目前已经不更新了,所以把目光投向了dubbox,dubbox是当当网基于dubbo二次开发的一个项目,dub ...
- POJ 3276 Face The Right Way (尺取法)
题目链接 Description Farmer John has arranged his N (1 ≤ N ≤ 5,000) cows in a row and many of them are f ...
- nodejs入门教程之http的get和request简介及应用
nodejs入门教程之http的get和request简介及应用 前言 上一篇文章,我介绍了nodejs的几个常用的模块及简单的案例,今天我们再来重点看一下nodejs的http模块,关于http模块 ...
- Windows下基于python3使用word2vec训练中文维基百科语料(二)
在上一篇对中文维基百科语料处理将其转换成.txt的文本文档的基础上,我们要将为文本转换成向量,首先都要对文本进行预处理 步骤四:由于得到的中文维基百科中有许多繁体字,所以我们现在就是将繁体字转换成简体 ...
- IOException while loading persisted sessions:
严重: IOException while loading persisted sessions: java.io.EOFException java.io.EOFException at java. ...
- GBK UTF-16 UTF-8 编码表
GBK UTF-16 UTF-8 ================== D2BB 4E00 E4 B8 80 一 B6A1 4E01 E4 B8 81 丁 C6DF 4E03 E4 ...