125. Valid Palindrome【easy】
125. Valid Palindrome【easy】
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) {
int start = , end = s.length() - ;
while (start <= end) {
if (!isalnum(s[start])) {
start++;
} else if (!isalnum(s[end])) {
end--;
} else {
if (tolower(s[start++]) != tolower(s[end--])) {
return false;
}
}
}
return true;
}
};
125. Valid Palindrome【easy】的更多相关文章
- 680. Valid Palindrome II【easy】
680. Valid Palindrome II[easy] Given a non-empty string s, you may delete at most one character. Jud ...
- 234. Palindrome Linked List【easy】
234. Palindrome Linked List[easy] Given a singly linked list, determine if it is a palindrome. Follo ...
- 661. Image Smoother【easy】
661. Image Smoother[easy] Given a 2D integer matrix M representing the gray scale of an image, you n ...
- 657. Judge Route Circle【easy】
657. Judge Route Circle[easy] Initially, there is a Robot at position (0, 0). Given a sequence of it ...
- 2. Trailing Zeros【easy】
2. Trailing Zeros[easy] Write an algorithm which computes the number of trailing zeros in n factoria ...
- 170. Two Sum III - Data structure design【easy】
170. Two Sum III - Data structure design[easy] Design and implement a TwoSum class. It should suppor ...
- 160. Intersection of Two Linked Lists【easy】
160. Intersection of Two Linked Lists[easy] Write a program to find the node at which the intersecti ...
- 206. Reverse Linked List【easy】
206. Reverse Linked List[easy] Reverse a singly linked list. Hint: A linked list can be reversed eit ...
- 203. Remove Linked List Elements【easy】
203. Remove Linked List Elements[easy] Remove all elements from a linked list of integers that have ...
随机推荐
- small test on 5.30 morning T3
经典的等价类计数问题,我们设 f(x) 为环长为 x 的时候的花环种类,那么答案显然等于 1/n * Σf( gcd (i,n) * [gcd(i,n)!=1] * [i>=0&&a ...
- 【博弈论】【SG函数】【枚举】bzoj1188 [HNOI2007]分裂游戏
因为第i个瓶子里的所有豆子都是等价的,设sg(i)表示第i个瓶子的sg值,可以转移到sg(j)^sg(k)(i<j<n,j<=k<n)的状态. 只需要考虑豆子数是奇数的瓶子啦, ...
- CSS box-flex属性,然后弹性盒子模型简介(转)
一.淡淡的开头语 昨天趁着不想工作的时间间隙闲逛24ways,在My CSS Wish List一文中,见到了个新鲜的CSS属性,就是题目中的box-flex,以前没有见过,顿生疑惑,不知是骡子还是马 ...
- ARM“庖丁解牛”之存储器管理单元MMU
转:http://blog.sina.com.cn/s/blog_a07635070101bcbt.html 最近笔者详细地学习了由杜春雷老师编写的<ARM体系结构与编程>.对ARM存储管 ...
- ajax请求不能下载文件(转载)
最近在做文件下载,后台写了个控制层,直接走进去应该就可以下载文件,各种文件图片,excel等 但是起初老是下载失败,并且弹出下面的乱码: 前台请求代码: $('#fileexcel').unbind( ...
- 监控Coherence成员的加入和离开集群事件
对server事件的监控主要是实现MemberListener类,对Cache事件的监控主要通过MapListener 参考代码 package coherencetest; import com.t ...
- 面试题:Java中值传递和引用传递的问题
随便写写留着自己看. 首先,Java的参数传递,不管是基本数据类型还是引用类型的参数,都是按值传递,没有按引用传递! 当一个实例对象作为参数被传递到方法中时,参数的值就是该对象的引用的一个副本.指向同 ...
- Myeclipse中文件已经上传到server文件夹下,文件也没有被占用,可是页面中无法读取和使用问题的解决方法
这个问题是因为Myeclipse中文件不同步引起的.在Myeclipse中,project文件是由Myeclipse自己主动扫描加入的,假设在外部改动了project文件夹中的文件但又关闭了自己主动刷 ...
- Laravel 5系列教程二:路由,视图,控制器工作流程
免费视频教程地址https://laravist.com/series/laravel-5-basic 上一篇教程我们走了那么长的路,终于把Laravel安装好了,这一篇教程我们就要进入Laravel ...
- JavaScript 数字与字符串 比较大小
总结一下JS中经常遇到纯数字和各种各样的字符串进行比较: 纯数字之间的比较 alert(1<3);//true 数字字符串比较,会将其先转成数字 alert("1"<& ...