[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 ...
随机推荐
- angularjs实现 checkbox全选、反选的思考
之前做了一周的打酱油测试,其实感觉其实测试也是上辈子折翼的天使. 好长时间没写代码,感觉好多都不会了. 感谢这周没有单休,我能看熬夜看奥运了.我能有时间出去看个电影,我能有时间出去逛个商城,我能有时间 ...
- service对象
Service 对象 提供用于创建服务程序的一组工具 语法 Shell.Service[.property|method] 属性 Description 服务描述,仅限于 Windows 2000 及 ...
- java web _BBS
在注册时用户输入用户名和密码不合格在旁边提示 在用户发言带有屏蔽字时应在旁边提示,但不影响其发送,只是在显示时屏蔽关键字
- 基于Linux 的VM TOOLS Install
VMware Tools Install 在VMware中为Linux系统安装VM-Tools的详解教程 如果大家打算在VMware虚拟机中安装Linux的话,那么在完成Linux的安装后,如果没 ...
- leetcode 160
160. Intersection of Two Linked Lists Write a program to find the node at which the intersection of ...
- const int * p 和 int const * p 和 int * const p 的区别
首先注意,const int * p 和int const *p 是一样的,并且不管是不是*p,即使const int i和int const i也是一样的,所以我们接下来只讨论int const * ...
- java集合类(二)
第十六天知识点总结 一.泛型 泛型:java jdk 1.5 新特性. 泛型的好处: 1.运行时的错误提前到编译时. 2.避免无谓的强制类型转换 自定义方法泛型:自定义泛型就是一个数据类型的占位或一个 ...
- flex中通过sprite在地图上画柱状图主要代码
1.主要代码: var sprite:Sprite = new Sprite(); var columnSys:ColumnSymbol = new ColumnSymbol(); v ...
- 【DIOCP知识库】连接上下文TIocpClientContext
来自弦子介绍 [概述] 该类管理远程连接,每一个远程连接会对应一个该类的实例,开发时可以通过继承该类,扩展属性,可以存储更多的连接信息,可以重写OnRecvBuffer方法进行数据逻辑的处理 [字段/ ...
- (十二) 一起学 Unix 环境高级编程 (APUE) 之 进程间通信(IPC)
. . . . . 目录 (一) 一起学 Unix 环境高级编程 (APUE) 之 标准IO (二) 一起学 Unix 环境高级编程 (APUE) 之 文件 IO (三) 一起学 Unix 环境高级编 ...