[Leetcode][JAVA] Valid Palindrome
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.
应该算是leetcode上最简单的题之一了吧。双指针可搞定。。
public boolean isPalindrome(String s) {
int i=0;
int j=s.length()-1;
while(i<j) {
if(!Character.isLetterOrDigit(s.charAt(i))) {
i++;
continue;
}
if(!Character.isLetterOrDigit(s.charAt(j))) {
j--;
continue;
}
if(Character.toLowerCase(s.charAt(i))!=Character.toLowerCase(s.charAt(j)))
return false;
i++;
j--;
}
return true;
}
[Leetcode][JAVA] Valid Palindrome的更多相关文章
- [LeetCode] 680. Valid Palindrome II 验证回文字符串 II
Given a non-empty string s, you may delete at most one character. Judge whether you can make it a pa ...
- leetcode 125. Valid Palindrome ----- java
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- Java [Leetcode 125]Valid Palindrome
题目描述: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ...
- LeetCode 1216. Valid Palindrome III
原题链接在这里:https://leetcode.com/problems/valid-palindrome-iii/ 题目: Given a string s and an integer k, f ...
- [LeetCode] 125. Valid Palindrome 验证回文字符串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- [leetcode] 1. Valid Palindrome
leetcode的第一题,回文数判断. 原题如下: For example, "A man, a plan, a canal: Panama" is a palindrome. & ...
- 【leetcode】Valid Palindrome
题目简述: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ...
- 【题解】【字符串】【Leetcode】Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- LeetCode 125. Valid Palindrome
这个题目只要注意大小写问题即可解决,而且我们只关注的是字母和数值 Given a string, determine if it is a palindrome, considering only a ...
随机推荐
- Linux操作系统学习笔记
关于Linux详细介绍可以参见:http://blog.csdn.net/hguisu/article/details/6122513 关于Linux的常用命令可以参见:http://blog.csd ...
- sqlserver复制报”应用复制的命令时在订阅服务器上找不到该行“解决方法
最近遇到“应用复制的命令时在订阅服务器上找不到该行”问题,报错如下: 官方给出的建议是重新同步和初始化订阅,当然,这是一种选择,但是对于动辄上百G的生产库,这种方法会消耗大量的资源和时间.可以通过定位 ...
- 【转】linux下skype的安装使用
http://hi.baidu.com/24_jason/item/f85725306c7dbcf5df2221ca Fedora 18/17, CentOS/RHEL/SL 6.3 安装 Skype ...
- dubbo问题总结
1.dubbo序列化数据丢失问题.dubbo的返回结果是对象,那么必须要实现对象中需要返回的数据的get方法. 2.dubbo序列化问题.
- KBMMW 4.90.00 发布
kbmMW is a portable, highly scalable, high end application server andenterprise architecture integra ...
- CLR VIA C#事件
事件是类型的一个成员,用来在事情发生的时候通知注册了该事件的成员. 事件和观察者模式十分的相似,所以事件应该提供如下几种能力 1.能让对象的方法登记对他的关注 2.能让对象的方法取消对他的关注 3.能 ...
- Android 下拉刷新框架实现
原文地址:http://blog.csdn.net/leehong2005/article/details/12567757 前段时间项目中用到了下拉刷新功能,之前在网上也找到过类似的demo,但这些 ...
- asp.net截取指定长度的字符串内容
/// <summary> /// 用于截取指定长度的字符串内容 /// </summary> /// <param name="sString"&g ...
- 校验日期函数的js
/判断输入内容是否为空 function IsNull(){ var str = document.getElementById('str').value.trim(); if(str.length= ...
- Python-内置类属性
Python内置类属性 __dict__ : 类的属性(包含一个字典,由类的数据属性组成) __doc__ :类的文档字符串 __name__: 类名 __module__: 类定义所在的模块(类的全 ...