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 ...
随机推荐
- [BZOJ2876]骑行川藏
以前并没有发现微积分教材上有这种东西...我还是太菜了... 其实就是要在满足$\sum\limits_{i=1}^nk_is_i(v_i-v_i')^2\leq E$的同时求$\sum\limits ...
- WebSocket 实战(转)
WebSocket 实战 本文介绍了 HTML5 WebSocket 的由来,运作机制及客户端和服务端的 API 实现,重点介绍服务端(基于 Tomcat7)及客户端(基于浏览器原生 HTML5 AP ...
- 数据结构之B-树,你每天都在用的,源码发布!
五一前就筹划着写下这篇文章,但是迫于自己从来没有实现过B-树(如果大家感兴趣,我可以考虑写一篇B+树的文章),手中没有源代码,另外自己以前对B-树也是一知半解状态中,担心误人子弟,在4月30日终于把代 ...
- 【OpenJudge8464】【序列DP】股票买卖
股票买卖 总时间限制: 1000ms 内存限制: 65536kB [描述] 最近越来越多的人都投身股市,阿福也有点心动了.谨记着“股市有风险,入市需谨慎”,阿福决定先来研究一下简化版的股票买卖问题. ...
- 触摸事件onTouchListener
1.效果图: (1)MainAcivity.java package com.example.app3; import android.content.DialogInterface; import ...
- Orcale自增/Hibernate 配置
-- 自增 create sequence SEQ_T_APP_USER start with 1 increment by 1; -- 触发器 create trigger DECTUSER_T_ ...
- 连接zookeeper集群
连接到ZooKeeper集合 ZooKeeper类通过其构造函数提供connect功能.构造函数的签名如下 : ZooKeeper(String connectionString, int sessi ...
- MVC架构、WebForm与MVC对比
ylbtech-ASP.NET MVC:WebForm与MVC对比 功能描述:WebForm与MVC对比 A.1,MVC架构 •MVC(Model-View-Controller)用于表示一种软件架构 ...
- UI 层级问题
UI 用overlay的话 不会有自己的camre 直接画到backbuffer上 比较推荐 分层的事情就用sorting order解决就可以了 下一步就是能不能拿到 ugui的shader了 UI ...
- https://v2ex.com/t/170386
https://v2ex.com/t/170386 https://cnodejs.org/topic/5566952ad4ca459f5267ac59 https://segmentfault.co ...