125. Valid Palindrome
来源:互联网 发布:知轩藏书 编辑:程序博客网 时间:2024/06/05 10:15
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.
public class Solution { public boolean isPalindrome(String s) { if(s.length()==0) return true; int low=0; int high=s.length()-1; while(low<=high){ while(low<=high&&(!valid(s.charAt(low)))) low++; while(high>=low&&(!valid(s.charAt(high)))) high--; if(low>=high) return true; if(change(s.charAt(low))!=change(s.charAt(high))) return false; low++; high--; } return true; } static boolean valid(char c){ if((c>='a'&&c<='z')||(c>='A'&&c<='Z')||(c>='0'&&c<='9')) return true; else return false; } static char change(char c){ if(c>='a'&&c<='z'){ char temp=(char)(c-('a'-'A')); return temp; } return c; }}
0 0
- [LeetCode]125.Valid Palindrome
- LeetCode 125. Valid Palindrome
- [Leetcode] 125. Valid Palindrome
- 【LeetCode】125.Valid Palindrome
- [leetcode] 125.Valid Palindrome
- 125. Valid Palindrome
- [leetcode] 125.Valid Palindrome
- Leetcode 125. Valid Palindrome
- 125. Valid Palindrome
- 125. Valid Palindrome LeetCode
- 125. Valid Palindrome
- 【LeetCode】125. Valid Palindrome
- 125. Valid Palindrome
- 125. Valid Palindrome
- Leetcode 125. Valid Palindrome
- LeetCode 125. Valid Palindrome
- LeetCode 125. Valid Palindrome
- LeetCode *** 125. Valid Palindrome
- 又是一个新开始
- nginx 下 thinkphp 502 bad Gateway + "LNMP一键安装包的Nginx 502 Bad Gateway错误可能原因及解决方法"
- 常见的数据结构与算法(上)
- 安卓图片终极压缩 尺寸和质量
- 安装lxml HTML 解析器,需要c语言库? BeautifulSoup
- 125. Valid Palindrome
- 将选中的物体进行修改保存到XML或者保存到Assets目录下的某个预制以及自定义快捷键=_=
- FreeRTOS 任务调度 系统节拍
- 代码中的减法
- hibernate配置
- 预处理
- jQuery Mobile 入门教程[转]
- Spring AOP的配置
- Anaconda多环境多版本python配置指导