125. Valid Palindrome
来源:互联网 发布:微信好友定位软件 编辑:程序博客网 时间:2024/06/05 04:32
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..
先扫一遍忽略空格,塞到char[]里面,从两端检测
public class Solution { public boolean isPalindrome(String s){int len=s.length();if(len==0)return true;char[] carr=new char[len];int cnt=0;for(int i=0;i<len;i++){char c=s.charAt(i);if(c>='0'&&c<='9'||c>='a'&&c<='z'||c>='A'&&c<='Z')carr[cnt++]=c;}String str=new String(carr, 0, cnt);str=str.toLowerCase();int size=str.length();for(int i=0,j=size-1;i<size;i++,j--)if(str.charAt(i)!=str.charAt(j))return false;return true;}}
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
- LintCode(easy)字符串查找(bug集)
- 通过Eclipse使用OpenCV Java
- NIO:Buffer 详解
- noip 2004-合唱队形-dp
- C++拷贝构造函数
- 125. Valid Palindrome
- C6000系列DSP的GPIO模块
- HDOJ 5742 (2016多校联合训练 Training Contest 2) It's All In The Mind
- opengl颜色混合
- wifi详解3
- mySql创建函数
- 长按 删除 ListView选项
- linux下如何查看系统和内核版本
- IOS开发UI篇--IOS动画(Core Animation)总结