125 Valid Palindrome
public class Solution {
public boolean isPalindrome(String s) {
if(s==null)
return false;
s=s.toLowerCase();
for(int i =0,j=s.length()-1;i<=j;i++,j--){
while(!isAlpha(s.charAt(i))&&!isNum(s.charAt(i))){
i++;
if(i>j)
break;
}
while(!isAlpha(s.charAt(j))&&!isNum(s.charAt(j))){
j--;
if(i>j)
break;
}
if(i<=j){
if(s.charAt(i)!=s.charAt(j)){
return false;
}
}
}
return true;
}
public boolean isAlpha(char a){
if((a >= 'a' && a <= 'z') || (a >= 'A' && a <= 'Z')){
return true;
}else{
return false;
}
}
public boolean isNum(char a){
if(a >= '0' && a <= '9'){
return true;
}else{
return false;
}
}
}
125 Valid Palindrome的更多相关文章
- 125. Valid Palindrome【easy】
125. Valid Palindrome[easy] Given a string, determine if it is a palindrome, considering only alphan ...
- [LeetCode]题解(python):125 Valid Palindrome
题目来源 https://leetcode.com/problems/valid-palindrome/ Given a string, determine if it is a palindrome ...
- leetcode 125. Valid Palindrome ----- java
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 ...
- 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 ig ...
- 【一天一道LeetCode】#125. Valid Palindrome
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given 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 ...
- 125. Valid Palindrome (Array; Two-Pointers)
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
随机推荐
- Flask——route
Flask——route 关于路由flask中有三种方法(例子)处理: flask.Flask.route 装饰器(关于装饰器可以参考该文),这时最常见的使用方法,在装饰器的参数中加入想要的路由即可, ...
- MySQL_杭州北仓 12.3-12.7需求活动期间累计下单达到3天及以上的客户_20161212
#C025_02杭州北仓 12.3-12.7需求活动期间累计下单达到3天及以上的客户明细 SELECT d.*,CASE WHEN 下单天次>=3 THEN "下单超过3天" ...
- poj 2987 最大权闭合图
Language: Default Firing Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 8744 Accept ...
- Intel 82599 万兆网卡
http://www.cnblogs.com/zhuyp1015/archive/2012/08/23/2653264.html http://bbs.chinaunix.net/thread-424 ...
- 【Tyvj1601】魔兽争霸(主席树,树套树)
题意:要求在N个数的序列中支持以下操作: 1:将第X个元素加上Y 2:询问当前K大值 n<=30000,m<=50000 思路:树状数组套主席树 Tyvj又炸了,还不知道对不对 ..12] ...
- TFS与Eclipse、Microsoft Visual Studio等客户端以webservice进行交换。
TFS与eclipse.Microsoft Visual Studio等客户端以webservice进行交互. 参考地址: http://server_ip:8080/tfs/项目区域/version ...
- CodeForces 607C (DP) Hard problem
题目:这里 题意:给定n个字符串,每个字符串可以进行一项操作,就是将这个字符串交换,就是该字符串的第一个和最后一个交换,第二个和倒数第二个交换,以此类推,当然可以选择对于 该字符串进行或不进行这项操作 ...
- 烧写AT91Bootstrap不能连接SAM-BA的解决方法
AT91与SAM-BA的连接是由于芯片内有一段固化的代码运行起来后才会检测到目标板并建立连接. 假设现在你烧写了Bootstrap进去,芯片上电后发现有可运行的代码,从而就不执行片内固化的那个代 ...
- Android -- The Manifest File
Before the Android system can start an app component, the system must know that the component exists ...
- 1064. Complete Binary Search Tree (30)
分析: 考察BST + 完全二叉树的性质,注意: (1):先用排序排好,然后由于是完全二叉树,我们使用中序来建树. (2):建好之后,层次遍历可以采用队列. #include <iostream ...