valid-palindrome
来源:互联网 发布:蚁群算法VB程序 编辑:程序博客网 时间:2024/06/16 21:51
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.
判断回文串,两个指针
代码:
class Solution {public: bool isPalindrome(string s) { if(s.length()==0) return true; int i,j; for(i = 0,j = s.length()-1;i<j;++i,--j){ while(i < j && !isalnum(s[i]))//测试用例里有数字,所以用isalnum而不能用isalpha ++i; while(i < j && !isalnum(s[j])) --j; if(tolower(s[i])!=tolower(s[j]))//别忘了转成小写比较 return false; } return true; }};
阅读全文
0 0
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- valid palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- Valid Palindrome
- 创建FTP服务器
- OpenCV图像边缘检测(Laplace算法)
- 更改WebStorm代码模板
- jdk集合类
- Android—SharedPreferences的使用
- valid-palindrome
- 解决错误"SLF4J: Failed to load class 'org.slf4j.impl.StaticLoggerBinder'"
- winxp MySQL 5.6.35 免安装版 简单配置
- CSS基础知识
- 卷积神经网络CNN(7)—— 限速交通标志分类
- 基于KMP算法的C++字符串帮助类
- ReLu(Rectified Linear Units)激活函数
- 原来这样画表格速度更快,厉害!
- C语言实现双向链表