leetcode(valid-palindrome)判断字符串是否是对称
来源:互联网 发布:u盘坏了数据恢复 编辑:程序博客网 时间:2024/05/19 22:49
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.
解题方法:使用的是二分查找里面的快排算法。但是这里之判断大小写字母和所有的数字。
public class Solution { public boolean isPalindrome(String s) { if(s==null||s.length()==0||s.length()==1) return true; int i=0,j=s.length()-1; char left,right; while(i<j){ left=s.charAt(i); right=s.charAt(j); while(i<j&&!((left>='a'&&left<='z')||(left>='A'&&left<='Z')||(left>='0'&&left<='9'))){ i++; left=s.charAt(i); } if(left>='a'&&left<='z') left=(char) ('A'-'a'+left); while(i<j&&!((right>='a'&&right<='z')||(right>='A'&&right<='Z')||(right>='0'&&right<='9'))){ j--; right=s.charAt(j); } if(right>='a'&&right<='z') right=(char) ('A'-'a'+right); if(left-right==0){ i++; j--; }else return false; } return true; }}
0 0
- leetcode(valid-palindrome)判断字符串是否是对称
- Valid Palindrome 判断一个字符串是否是回文串
- leetcode 判断有效字符串是回文串Valid Palindrome
- 判断是否是回文(Valid Palindrome)
- (LeetCode)Valid Palindrome --- 判断回文字符串
- 判断一个字符串是否是对称字符串
- Leetcode 字符串 Valid Palindrome
- 判断是否是回文串(Valid Palindrome)
- Valid Palindrome 检查是否是有效的回文 @LeetCode
- 判断字符串是否对称
- 判断字符串是否对称
- 判断字符串是否对称
- 判断字符串是否对称
- 判断字符串是否对称
- 判断字符串是否对称
- LeetCode 125. Valid Palindrome(校验对称)
- LeetCode Valid Number(判断字符串是否是合法的数字表示 )
- 黑马程序员_判断一个字符串是否是对称字符串
- 监听屏幕 android.intent.action.USER_PRESENT
- BZOJ 2096
- CSS3实现“圣杯布局”--(固比固布局)
- java线程面试题
- join控制线程的执行顺序
- leetcode(valid-palindrome)判断字符串是否是对称
- Java 教程目录
- CF355div2
- 位运算求两个数的平均值
- Hbase编程实践
- JACK编译器配置
- Ubuntu设置环境变量
- 从内存中加载映像(EXE/DLL)到本地或者远程进程执行
- POI