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 ...
随机推荐
- IDEA的Maven项目找不到class
- [BZOJ5465][APIO2018]选圆圈(KD-Tree)
题意:给你n个圆,每次选择半径最大的,将它和与它相交的圆全部删去,输出每个圆是在哪次被删的. KD树模板题.用一个矩形框住这个圆,就可以直接剪枝了.为了防止被卡可以将点旋转一个角度,为了保险还可以多转 ...
- C语言实现汉诺塔问题
代码如下: #include <stdio.h> #include <stdlib.h> void move(int n,char x,char y,char z) { ) { ...
- PythonGUI编程--向列表框添加滚动条
代码如下: from tkinter import * window = Tk() window.title("New England") yscroll = Scrollbar( ...
- python中的else子句
在一般的语言中else子句一般是紧跟在if 子句后面,但是python语言中else子句可以不跟在if子句后面,请看下面代码: >>> for n in range(2, 10): ...
- [测试技术分享]easyFuzzer使用案例分享
easyFuzzer使用案例分享 1.简介: easyFuzzer是wooyun的一位白帽子(光刃)提供的一款用于fuzz文件的工具.平时主要是和网络协议安全打交道,和本地软件安全打交道比较少,所以没 ...
- 三星s3c24xx平台GPIO操作详解
转:http://blog.chinaunix.net/uid-22030783-id-3391515.html 先介绍三星S3C24XX平台BSP中定义外设寄存器和GPIO的相关头文件 以linux ...
- 【JAVA】StringTokenizer 迭代方式对字符串进行分割
StringTokenizer是一个用来分隔String的应用类,相当于VB的split函数.1.构造函数public StringTokenizer(String str)public String ...
- 分页 返回 json格式数据
分页工具类PageBean.java package org.activeii.activeii.app.person.util; import java.util.List; public clas ...
- git学习——分支
分支 创建分支:git branch 如:git branch testing Git通过HEAD指针知道用户是在哪一个分支上工作. 切换分支用git checkout命令,注意:可以用git sta ...