Valid Palindrome
来源:互联网 发布:如寡人者安与知耻的知 编辑:程序博客网 时间:2024/05/17 05:50
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.
Java代码:public class Solution { public boolean isPalindrome(String s) { int start =0;int end = s.length()-1;while(start < end){while((s.charAt(start)<'A' || s.charAt(start)>'z' || (s.charAt(start)>'Z' && s.charAt(start)<'a')) && start<s.length()-1 && (s.charAt(start)<'0' || s.charAt(start)>'9'))start++;while((s.charAt(end)<'A' || s.charAt(end)>'z' || (s.charAt(end)>'Z' && s.charAt(end)<'a')) && end>0 && (s.charAt(end)<'0' || s.charAt(end)>'9'))end--;if(start < end){if(s.charAt(start) == s.charAt(end) ||s.charAt(start)+32 == s.charAt(end) || s.charAt(start)-32 == s.charAt(end)){start++;end--;}else{return false;}}}return true; }}
0 0
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- valid palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Android手机目前常见的分辨率
- [Hb-X] 课程设计I(寻址 数字转字符串 除法溢出 显示字符串)
- 苹果apns推送总结
- 16周课后自主-项目4-动态数组
- Java包装类
- Valid Palindrome
- DB2错误码汇总
- 点到圆的最近距离公式推导
- 问题列表
- 移植tcpdump到arm linux
- Leetcode_107_Binary Tree Level Order Traversal II
- Ubuntu14.04下安装qq
- org.springframework.context.ApplicationContextAware
- 第十六周项目2-7:比较两个字符串,返回值同strcmp()