Valid Palindrome

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
 
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.

Challenge

O(n) time without extra memory.

深刻体会到了英文的用处。。。题目的中文翻译真是误导人。

 public class Solution {
/**
* @param s A string
* @return Whether the string is a valid palindrome
*/
public boolean isPalindrome(String s) {
char[] cs = s.toCharArray();
int i = 0;
int j = cs.length - 1; while(i<j) {
while(i<j && !Character.isDigit(cs[i]) && !Character.isLetter(cs[i])) i++;
while(i<j && !Character.isDigit(cs[j]) && !Character.isLetter(cs[j])) j--;
if(i >= j) break;
String ss = cs[i] + "";
String ss1 = cs[j] + "";
if(!ss.equalsIgnoreCase(ss1))
return false; i++;
j--;
}
return true;
}
}

最新文章

  1. 关于.9.png格式图片的制作与使用
  2. sql server 常见错误代码15000 - 15999含义解析
  3. 汇编学习(一)&mdash;&mdash;win7 64位调出debug
  4. HackerRank &quot;Minimum Penalty Path&quot;
  5. gerrit 调试smtp email
  6. 使用Varnish代替Squid做网站缓存加速器的详细解决方案----转载
  7. sqlserver 字符串相关函数
  8. HDU4349--Xiao Ming&#39;s Hope(数论)
  9. Linux下搭建Oracle11g RAC(1)----IP分配与配置IP
  10. Linux下得到显示屏参数的方法
  11. [转]ActiveMQ 即时通讯服务 浅析
  12. 環氧樹脂對COB的影響
  13. Java网络编程:利用apache的HttpClient包进行http操作
  14. Angularjs,WebAPI 搭建一个简易权限管理系统
  15. java练习 - 字符串反转
  16. 《java.util.concurrent 包源码阅读》21 CyclicBarrier和CountDownLatch
  17. js与jQuery的区别——每日一记录
  18. mysql---select的五种子句学习(where、group by、having、order by、limit)
  19. Java学习笔记47(JDBC、SQL注入攻击原理以及解决)
  20. 20155302 2016-2017-2 《Java程序设计》第九周学习总结

热门文章

  1. 阿里云maven仓库地址,速度提升100倍
  2. android设计准则
  3. android程序员成长路径的思考
  4. PHP正则 贪婪匹配与非贪婪匹配
  5. 20155335俞昆《java程序设计》第十周总结
  6. C函数前向声明省略参数
  7. api文档工具
  8. C后端设计开发 - 第1章-流派-入我华山,学我剑法
  9. aspxpivotgrid 导出excel时,非绑定咧显示为0的情况
  10. [How to] 真机调试