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 ...
随机推荐
- 【动态规划】【记忆化搜索】CODEVS 1011 数的计算 2001年NOIP全国联赛普及组
设答案为f(n),我们显然可以暴力地递归求解: f(n)=f(1)+f(2)+……+f(n/2). 但是n=1000,显然会超时. 考虑状态最多可能会有n种,经过大量的重复计算,所以可以记忆下来,减少 ...
- [POI2018]Plan metra
题目大意: 一棵$n(n\le5\times10^5)$个结点的树,每条边的边权均为正整数,告诉你$2\sim n-1$号结点到$1$号点和$n$号点的距离$d1[i]$和$d2[i]$.求是否存在这 ...
- [CF321C]Ciel the Commander
题目大意: 给你一棵n个结点的树,给每个结点分级,最高为'A',最低为'Z'. 尝试构造一种分级方案,使得任意两个相同级别的结点路径上至少有一个更高级的结点. 思路: 贪心+树上点分. 递归处理每一棵 ...
- cocos2d-x引擎优化 修改记录
3.13 一些无聊的bug etc1 在android 平台不能正常显示,包括 cc.Button,setGray,clipeNode 3.13.1优化记录 7月 2.公式计算改为长整型, ...
- UILabel设置行间距
UILabel设置行间距: NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWi ...
- 表或视图不存在 Hibernate Oracle
曾经运行一个别人写的程序,之前连的别人的机器的数据,后来我把数据导入到本地数据库中运行,出错,如下:Hibernate: select sum(rdb_alert_0_.EVENT_COUNT) as ...
- P2P通信标准协议(二)之TURN
上一篇P2P通信标准协议(一)介绍了在NAT上进行端口绑定的通用规则,应用程序可以根据这个协议来设计网络以外的通信. 但是,STUN/RFC5389协议里能处理的也只有市面上大多数的Cone NAT( ...
- Nginx用作反向代理服务器
Nginx作为反向代理服务器时转发请求的流程 客户端请求处理 当客户端请求来时,Nginx并不会立刻转发到上游服务器,而是想完整的接收到Nginx所在的服务器, 然后再把缓存的客户端的请求转发到上游服 ...
- Shader and Program编程基本概念 - 转
原地址:http://blog.csdn.net/myarrow/article/details/7737313 一.本文关注的问题: • Shader and program 对象介绍• 创建并编译 ...
- JavaScript字符串api简单说明
1.可返回指定位置的字符 stringObject.charAt(index); 2.返回的是位于指定位置的字符的编码 stringObject.charCodeAt(index); 3.用于连接两个 ...