leetCode(51):Valid Palindrome
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.empty())
return true;
int i=0;
int j=s.size()-1;
for(;i<j;i++)
{//i后移
if((s[i]>='a' && s[i]<='z') || (s[i]>='A' && s[i]<='Z') || (s[i]>='0' && s[i]<='9'))
{//找到第一个为字符或数字的字符
for(;j>i;--j)
{//j前移
if((s[j]>='a' && s[j]<='z') || (s[j]>='A' && s[j]<='Z') || (s[j]>='0' && s[j]<='9'))
{//找到第一个为字符或数字的字符
if(s[i]==s[j] || s[i]+'A'-'a'==s[j] || s[i]+'a'-'A'==s[j])
{//找到后时行推断
j--;//前进一步
break;
}
else
return false;
}
}
}
}
return true;
}
};
leetCode(51):Valid Palindrome的更多相关文章
- [LeetCode] 680. Valid Palindrome II 验证回文字符串 II
Given a non-empty string s, you may delete at most one character. Judge whether you can make it a pa ...
- [Leetcode][JAVA] Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- [leetcode] 1. Valid Palindrome
leetcode的第一题,回文数判断. 原题如下: For example, "A man, a plan, a canal: Panama" is a palindrome. & ...
- LeetCode 1216. Valid Palindrome III
原题链接在这里:https://leetcode.com/problems/valid-palindrome-iii/ 题目: Given a string s and an integer k, f ...
- [LeetCode] 125. Valid Palindrome 验证回文字符串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- 【leetcode】Valid Palindrome
题目简述: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ...
- 【题解】【字符串】【Leetcode】Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- leetcode 125. Valid Palindrome ----- java
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- LeetCode 125. Valid Palindrome
这个题目只要注意大小写问题即可解决,而且我们只关注的是字母和数值 Given a string, determine if it is a palindrome, considering only a ...
随机推荐
- 计算机、程序和java概述
1.1 计算机.程序和java概述计算机包括硬件(hardware)软件(software)两部分.硬件包括计算机中看得见的物理部分,软件提供看不见的指令,指令控制硬件并且使得硬件完成特定的任务.一台 ...
- Unity 过度光照贴图
背景:开关窗帘过程,让环境在亮和暗之间过度 事先烘培出亮.暗两张Lighting map.然后代码实现,窗帘开关由动作实现,而代码中通过动作执行进度来过度两张Lighting map void OnA ...
- zoj 2974 Just Pour the Water矩阵快速幂
Just Pour the Water Time Limit: 2 Seconds Memory Limit: 65536 KB Shirly is a very clever girl. ...
- 【NOIP2017】逛公园(最短路图,拓扑排序,计数DP)
题意: 策策同学特别喜欢逛公园. 公园可以看成一张 N 个点 M 条边构成的有向图,且没有自环和重边.其中 1 号点是公园的入口, N 号点是公园的出口,每条边有一个非负权值,代表策策经过这条边所要花 ...
- ADO:DataSet合并两张表( ds.Merge(ds1))
原文发布时间为:2008-08-01 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Data;using System.Configuration ...
- 根据已知日期(yyyy-MM-dd)获取前n天的日期区间
//获取天 var pubTime="2017-12-30" function buildDay(num){ num=num-1; var myDate = new Date(pu ...
- 【MFC】利用单一对话框内的分页技术实现向导功能(转)
原文转自 http://blog.csdn.net/yongh701/article/details/43793151 所谓的向导功能,在win32的程序中常常见于安装程序或者程序内的设置向导,该向导 ...
- 关于nginx所遇问题
1. 如果出现 nginx: [error] invalid PID number “” in “/usr/local/var/run/nginx/nginx.pid” 错误重新加载配置文件 /usr ...
- LeetCode OJ--Longest Consecutive Sequence ***
http://oj.leetcode.com/problems/longest-consecutive-sequence/ 起初想的是排序,查了下O(n)的排序算法有计数排序.基数排序.桶排序.后来考 ...
- latex beamer 插入代码
有网友在beamer中使用mcode也就是 listings 输出源代码时遇到如下错误: Runaway argument?! Paragraph ended before \lst@next was ...