Java for LeetCode 125 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.
解题思路:
注意题目,忽略大小写,忽略非字母或数字,JAVA实现如下:
public boolean isPalindrome(String s) {
if(s.length()<=1)
return true;
int left=0,right=s.length()-1;
while(left<right){
if(!Character.isLetterOrDigit(s.charAt(left))){
left++;
continue;
}
if(!Character.isLetterOrDigit(s.charAt(right))){
right--;
continue;
}
if(Character.toUpperCase(s.charAt(left))!=Character.toUpperCase(s.charAt(right)))
return false;
left++;
right--;
}
return true;
}
Java for LeetCode 125 Valid Palindrome的更多相关文章
- 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] 125. 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 ...
- [leetcode]125. Valid Palindrome判断回文串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- LeetCode 125 Valid Palindrome(有效回文)(*)
翻译 给定一个字符串.确定它是否是回文的,仅仅考虑当中的数字和字符并忽略其它. 比如. "A man, a plan, a canal: Panama" 是回文的. "r ...
- Leetcode 125 Valid Palindrome 字符串处理
题意:判断字符串是否是回文字符串 先将所有的字母和数字字符保留,并将大写字母转化成小写字母,然后将字符串倒置,比较前后两个字符串是否相同. 该题最好的解法可以模仿 Leetcode 345 Rever ...
- [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 ...
- 125. Valid Palindrome【easy】
125. Valid Palindrome[easy] Given a string, determine if it is a palindrome, considering only alphan ...
随机推荐
- Beginning Auto Layout Tutorial in iOS 7: Part 2
Auto Layout to the rescue! 接下来就看看如何使用Auto Layout来实现这个效果. 首先移除viewWillLayoutSubviews方法,选择Main.storybo ...
- zabbix监控系统-部署规划
- PHP生成月历代码
<?php /* Function Written by Nelson Neoh @3/2004. For those who wants to utilize this code, p ...
- 想给自己的实景三维模型做个案例集?Wish3D Earth再合适不过了
很多朋友向用户展示实景三维模型的时候经常面临这样的问题:
- JAVA Eclipse开发Android程序如何自定义图标
直接用做好的png图片替换res的所有分辨率的lc_launcher.png图片 注意到不同文件夹有不同的分辨率,直接把png图片做成最大的替换掉即可,不管小的. drawable-xxhdpi ...
- 【MVC2】发布到IIS上User.Identity.Name变成空
VS中运行时通过User.Identity.Name能取到用户名,发布到IIS上后,该值为空. 调查后发现在网站设定→[认证]中同时打开了[Windows认证]和[匿名认证], 关掉[匿名认证]后就能 ...
- 4种使用webpack提升vue应用的方式
本文参考自:https://mp.weixin.qq.com/s?src=11×tamp=1526886111&ver=889&signature=u9SixhvlJ ...
- vue修改数组元素方法
示例代码 <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF- ...
- C++中一些个函数的使用
函数:sprintf的使用 函数功能:把格式化的数据写入某个字符串 函数原型:int sprintf( char *buffer, const char *format [, argument] … ...
- http url转义字符,特殊字符
空格 - %20 " - %22 # - %23 % - %25 & - %26 ( - %28 ) - %29 + - %2B , - %2C / - %2F : - %3A ; ...