LintCode_415 有效回文串
给定一个字符串,判断其是否为一个回文串。只包含字母和数字,忽略大小写。
注意事项
你是否考虑过,字符串有可能是空字符串?这是面试过程中,面试官常常会问的问题。
在这个题目中,我们将空字符串判定为有效回文。
"A man, a plan, a canal: Panama" 是一个回文。
"race a car" 不是一个回文。
O(n) 时间复杂度,且不占用额外空间。
bool isPalindrome(string& s) {
// Write your code here
int len,j;
for(len = , j = ; j < s.size(); ++j)
{
if(s[j] >= '' && s[j] <= '')
{
s[len++] = s[j];
}
else if(((s[j] >= 'a') && (s[j] <= 'z')) || ((s[j] >= 'A') && (s[j] <= 'Z')))
{
s[len++] = tolower(s[j]);
}
}
int i = ;
j = len - ;
while(i < j)
{
if(s[i] == s[j])
{
i++;
j--;
}
else return false;
}
return true;
}
LintCode_415 有效回文串的更多相关文章
- [LeetCode] Longest Palindrome 最长回文串
Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...
- [LeetCode] Shortest Palindrome 最短回文串
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...
- [LeetCode] Palindrome Partitioning II 拆分回文串之二
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- [LeetCode] Palindrome Partitioning 拆分回文串
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- [LeetCode] Longest Palindromic Substring 最长回文串
Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...
- bzoj 3676 回文串 manachar+hash
考虑每个回文串,它一定是它中心字母的最长回文串两侧去掉同样数量的字符后的一个子串. 所以我们可以用manachar求出每一位的回文半径,放到哈希表里并标记出它的下一个子串. 最后拓扑排序递推就行了.. ...
- BZOJ 3676: [Apio2014]回文串
3676: [Apio2014]回文串 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 2013 Solved: 863[Submit][Status ...
- SPOJ - PLSQUARE Palin Squar(hash+回文串)
题意:给你一个n*n (n<=200)的字符串矩阵,问你每行每列都是回文串的最大的m*m的矩阵是多少 题解:首先答案不满足单调性,即m成立而m-1与m+1都却不一定成立,所以必须枚举答案确定现在 ...
- 删除部分字符使其变成回文串问题——最长公共子序列(LCS)问题
先要搞明白:最长公共子串和最长公共子序列的区别. 最长公共子串(Longest Common Substirng):连续 最长公共子序列(Longest Common Subsequence,L ...
随机推荐
- 【案例】鼠标按下,DIV跟随移动
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- js怎样截取字符串后几位以及截取字符串前几位
想要截取字符串前几位与后几位,主要代码如下 截取字符串前几位 var disName ='开心一族漂亮家园'; var shortName = disName.substring(0,5); cons ...
- CF1166D——数学公式思维题
#include<bits/stdc++.h> using namespace std; #define ll long long ll ans[],a,b,m; /* b=2^(n-2) ...
- mybatis分页插件PageHelp的使用
1.简介 PageHelper 是国内非常优秀的一款开源的 mybatis 分页插件,它支持基本主流与常用的数据库,例如 mysql.oracle.mariaDB.DB2.SQLite.Hsqld ...
- LUOGU P1337 [JSOI2004]平衡点 / 吊打XXX(模拟退火)
传送门 解题思路 学习了一下玄学算法--模拟退火,首先要求平衡处,也就是求势能最小的地方,就是求这个点到所有点的距离*重量最小.剩下的几乎是模拟退火的板子了. #include<iostream ...
- springboot与热部署
在开发中我们修改一个Java文件后想看到效果不得不重启应用,这导致大量时间花费,我们希望不重启应用的情况下,程序可以自动部署(热部署).有以下四种情况,如何能实现热部署. 1.模板引擎: 在Sprin ...
- light oj 1098 数学规律
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> ...
- vue 实现单选框
参考:https://blog.csdn.net/qq_42221334/article/details/81630634 效果: vue: <template> <div> ...
- css的其他相关样式属性
一.颜色 1.预定义的表示颜色的单词 red,black.gray,pink...... 2.16进制表示 # + 6位16进制的数字0 1 2 3 4 5 6 7 8 9 a b c d e f 如 ...
- 微信小程序发送手机验证码---倒计时
var currentTime = 59 //倒计时的事件(单位:s)var interval = null //倒计时函数 Page({ data: { time:59 //倒计时 }, onLoa ...