125. Valid Palindrome
来源:互联网 发布:认识linux服务器 编辑:程序博客网 时间:2024/06/05 18:47
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.
问题:判断一个字符串是否是回文字符串,只考虑字母和数字 忽略空格标点大小写等
思想:指针i 从前开始 指针j总后开始 向中间移动 ,当字符串为空串或者只有一个字符时它是回文的
public boolean isPalindrome(String s) { if(s==null||s.length()==1) return true; int i=0; int j=s.length()-1; while(i<=j){ char left=s.charAt(i); char right=s.charAt(j); if(!Character.isAlphabetic(left)&&!Character.isDigit(left)){ i++; } else if(!Character.isAlphabetic(right)&&!Character.isDigit(right)){ j--; } else{ //System.out.println("left="+left+"\tright="+right); left=Character.toLowerCase(left); right=Character.toLowerCase(right); if(left!=right) return false; i++;j--; } } 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
- tniker热修复命令行接入
- 超级强大的vim配置(vimplus)
- activiti5.18 建表测试
- python服务器环境搭建(1)——本地服务器准备
- Windows驱动开发:3 WRK调试环境搭建
- 125. Valid Palindrome
- STL算法排列
- go设置
- 对异步IO的理解
- L1-019. 谁先倒
- How to hide credential providers from Login Screen for Windows 7
- Android 多级菜单联动操作
- DS18B20
- 解决 div或者a标签的高度比里面的img高度多了5px 问题