[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 ...
随机推荐
- DOM编程(每天有学习一点篇)
每次想到“DOM”编程就会自然联想到“性能瓶颈”.我觉得有两部分原因: 1.DOM自己本身操作代价昂贵,因为浏览器通常要求DOM 实现和JavaScript 实现保持相互独立: 2.嘿嘿,本人自身的原 ...
- 模块化InnoSetup依赖项安装
原文在这里:http://www.codeproject.com/Articles/20868/NET-Framework-Installer-for-InnoSetup 源文件地址:http://w ...
- velocity模板使用建议
复杂页面前端模块化的方式: 方式一:iframe 方式二:velocity模板(#parse) 方式一,优点很多,也有缺点,例如页面之间传递参数等: 方式二,页面之间的调用,传参更容易,页面性能更好: ...
- web.xml的首页调用struts2的action解决方法
1,首先在struts.xml里添加如下代码:注意位置 <constant name="struts.action.extension" value="do,act ...
- ---Arch Linux 之AUR
只需下载压缩包,解压,进入文件夹,里面好像也只有一个PKBUILD文件,makepkg -s (自动下载程序然后编译打包), 然后pacman -U xxxx.pkg.xz 就好了
- 控件的相对位置与绝对位置-UI界面编辑器(SkinStudio)教程
绝对位置: 相对位置: 相对位置配合Anchor属性使用 例如Anchor属性选择left|top(即相对位置的left和top保持不变) 窗口大小改变前: 窗口大小改变后: 可以看到控件相对位置的l ...
- mininet之miniedit可视化操作
Mininet 2.2.0之后的版本内置了一个mininet可视化工具miniedit,使用Mininet可视化界面方便了用户自定义拓扑创建,为不熟悉python脚本的使用者创造了更简单的环境,界面直 ...
- JS回车事件,兼容目前所有浏览器
<script type="text/javascript" language=JavaScript charset="UTF-8"> docume ...
- jquery移动端日期插件
不说多的,直接看代码<!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- signtool.exe not found
When check the [sign the Xap File] checkbox, build project failed due to signtool.exe not found. Fol ...