125. Valid Palindrome
来源:互联网 发布:.儿童编程小游戏 编辑:程序博客网 时间:2024/05/22 16:45
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.
bool isAlphanumeric(char c) { if( (c >= '0' && c <= '9')|| (c >= 'a' && c <= 'z')|| (c >= 'A' && c <= 'Z')){ return true; }else{ return false; } }bool isSame(char a,char b){ if(a >= '0' && a <= '9'){ if(a == b){ return true; }else{ return false; } } if((a >= 'a' && a <= 'z')|| (a >= 'A' && a <= 'Z')){ if(abs(a-b) == 0 || abs(a-b) == 32){ return true; }else{ return false; } } return false;}bool isPalindrome(char* s) { char * start = NULL; char * end = NULL; if(s == NULL){ return true; } start = s; end = s + strlen(s) - 1; while(start < end){ while((!isAlphanumeric(*start))&&start < end){ start++; } while((!isAlphanumeric(*end))&&start < end){ end--; } if(start >= end ){ break; }else{ //printf("start = %c,end = %c\n\r",*start,*end); if(!isSame(*start,*end)){ return false; } start++; end--; } } 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
- 2017.9.10开学第二周总结(下)(周日比赛)
- java:动态代理的使用
- 制作可在MINI2440上运行的文件系统
- angular4中关于表单的校验
- HDOJ HDU 1082 Matrix Chain Multiplication
- 125. Valid Palindrome
- html5自带表单验证-美化改造
- C# byte数组与Image的相互转换
- BZOJ1085-骑士精神(A*搜索)
- C#--反射技术
- static和final两种修饰符
- Python2.数据类型和变量
- 丑数
- Git HEAD 意思详解 和版本回退