【字符串回文】Valid Palindrome
来源:互联网 发布:centos7 ubuntu 对比 编辑:程序博客网 时间:2024/05/23 16:54
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 char fun(char c){ if(c >= 'a' && c <= 'z') return c; if(c >= '0' && c <= '9') return c; return '#'; } public boolean isPalindrome(String s) { if(s == null || s.length()==0) return true; int len = s.length(); int left = 0; int right = len - 1; s = s.toLowerCase(); while(left < right){ char lc = '#'; while(left <= right){ lc = fun(s.charAt(left)); if(lc == '#') left++; else break; } char rc = '#'; while(left <= right){ rc = fun(s.charAt(right)); if(rc == '#') right--; else break; } if(lc == rc){ left++; right--; } else return false; } return true; }}
0 0
- 【字符串回文】Valid Palindrome
- Valid Palindrome(回文字符串)
- Valid Palindrome 判断回文字符串
- leetcode125---Valid Palindrome(回文字符串)
- leetcode 刷题:Valid Palindrome(回文字符串)
- (LeetCode)Valid Palindrome --- 判断回文字符串
- 125. Valid Palindrome (回文字符串判断)
- LeetCode Valid Palindrome(验证回文字符串)
- Valid Palindrome 回文
- 回文判定 Valid Palindrome
- Valid Palindrome有效回文
- Valid Palindrome 判断一个字符串是否是回文串
- LeetCode OJ 之 Valid Palindrome(回文字符串)
- leetcode 判断有效字符串是回文串Valid Palindrome
- <LeetCode>125.Valid Palindrome 验证回文字符串 Tag:string
- leetcode:Valid Palindrome 合法回文
- LeetCode - Valid Palindrome (判断“回文”)
- LeetCode (16) Valid Palindrome (回文)
- IOS-AutoresizesSubviews
- matlab 文件操作
- 黑马程序员_7k面试题之交通灯管理系统
- 2014阿里巴巴秋季软开笔试题
- 关于MFC使用 Unicode 字符集出现乱码的问题
- 【字符串回文】Valid Palindrome
- Erlang 进程被抢占的条件——一个进程长时霸占调度器的极端示例
- css中position:absolute|relative
- mysql中key 、primary key 、unique key 与index区别
- Nginx重新编译添加模块
- javascript--枚举算法实现
- matlab动画
- 2014阿里巴巴笔试(9/22北京站)
- Unity游戏开发--30s制作精美地图