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) {
int n=s.length();
if(n==) return true;
int i=,j=n-;
while(i<j){
if(!isCharacters(s[i])){
i++;
continue;
}
if(!isCharacters(s[j])){
j--;
continue;
}
int left=,right=,leftsig=,rightsig=;
left=(s[i]>=''&&s[i]<='')?s[i]-'':((s[i]>='a'&&s[i]<='z')?s[i]-'a':s[i]-'A');
right=(s[j]>=''&&s[j]<='')?s[j]-'':((s[j]>='a'&&s[j]<='z')?s[j]-'a':s[j]-'A');
leftsig=(s[i]>=''&&s[i]<='')?:;
rightsig=(s[j]>=''&&s[j]<='')?:;
if(left!=right||leftsig!=rightsig)
return false;
i++;
j--;
}
return true;
}
bool isCharacters(char c){
if((c>='a'&&c<='z')||(c>='A'&&c<='Z')||(c>=''&&c<=''))
return true;
else
return false;
}
};
valid-palindrome——判断带符号数字字母的字符串是否为回文的更多相关文章
- 【Teradata SQL】从中文数字字母混合字符串中只提取数字regexp_substr
目标:从中文数字字母的字符串中只提取数字 sel regexp_substr('mint choc中文11国1','\d+')
- 用递归方法判断字符串是否是回文(Recursion Palindrome Python)
所谓回文字符串,就是一个字符串从左到右读和从右到左读是完全一样的.比如:"level" .“aaabbaaa”. "madam"."radar&quo ...
- [leetcode]131. Palindrome Partitioning字符串分割成回文子串
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- javascript判断给定字符串是否是回文
//判断给定字符串是否是回文 function isPalindrome(word) { var s = new Stack(); for (var i = 0 ...
- AC日记——判断字符串是否为回文 openjudge 1.7 33
33:判断字符串是否为回文 总时间限制: 1000ms 内存限制: 65536kB 描述 输入一个字符串,输出该字符串是否回文.回文是指顺读和倒读都一样的字符串. 输入 输入为一行字符串(字符串中 ...
- C#进行回文检测,判断字符串是否是回文的代码
下面代码内容是关于C#进行回文检测,判断字符串是否是回文的代码,应该是对各位朋友有些好处. Console.WriteLine("算法1:请输入一个字符串!");string st ...
- YTU 2802: 判断字符串是否为回文
2802: 判断字符串是否为回文 时间限制: 1 Sec 内存限制: 128 MB 提交: 348 解决: 246 题目描述 编写程序,判断输入的一个字符串是否为回文.若是则输出"Yes ...
- Java - 判断字符串是否是回文
首先,回文是指类似于“12345”,“abcdcba”的形式,即正念和反念都是一样的字符串 判断字符串是否是回文,这边介绍3种办法 将字符串翻转,判断翻转后的字符串和原字符串是否相等 public s ...
- C语言:判断字符串是否为回文,-函数fun将单向链表结点数据域为偶数的值累加起来。-用函数指针指向要调用的函数,并进行调用。
//函数fun功能:用函数指针指向要调用的函数,并进行调用. #include <stdio.h> double f1(double x) { return x*x; } double f ...
随机推荐
- Python面试题(练习二)
1.用Python实现一个二分查找的函数. data = [1, 3, 6, 7, 9, 12, 14, 16, 17, 18, 20, 21, 22, 23, 30, 32, 33, 35] def ...
- Bootstrap-datepicker 用法
<div class="input-group input-daterange"> <input type="text" id="s ...
- JDBC 学习笔记(二)—— 详解 JDBC 的四种驱动类型
JDBC 有四种驱动类型,分别是: JDBC-ODBC 桥(JDBC-ODBC bridge driver plus ODBC driver) 本地 API 驱动(Native-API partly ...
- 将模型储存到本地-FastCoder
// // ViewController.m // 模型转data储存 // // Created by 谭启宏 on 16/3/4. // Copyright © 2016年 tqh. All ri ...
- Z-Score数据标准化处理(python代码)
#/usr/bin/python def Z_Score(data): lenth = len(data) total = sum(data) ave = float(total)/lenth tem ...
- 【Luogu】P4208最小生成树计数(状压乱搞)
题目链接 最小生成树有两个性质,两个性质都知道的话这题就变成码农题了. 1.无论最小生成树长什么样,所有权值的边的数量是不变的.比如我有棵最小生成树有两条权值为2的边四条权值为1的边,那这个图的所有最 ...
- 【Luogu】P4234最小差值生成树(LCT)
题目链接 能把LCT打得每个函数都恰有一个错误也是挺令我惊讶的. 本题使用LCT维护生成树,具体做法是对原图中的每个边建一个点,然后连边的时候相当于是将边的起点跟“边”这个点连起来,边的终点也跟它连起 ...
- java面试题之数据基本类型各占几个字节
类型 位数 字节数 short 2*8 2 char 2*8 2 int 4*8 4 float 4*8 4 long 8*8 8 double 8*8 8
- spring中MessageSource的配置使用方法2--ReloadableResourceBundleMessageSource
如何在spring mvc框架中实现MessageSource来管理国际资源文件呢 如下: 1.在applicationContext.xml文件内配置如下 <span style=" ...
- Wmap5 测试80端口 Your port 80 is actually used by :Server: Microsoft-HTTPAPI/2.0
问题:win7系统! 在wamp5的apache启动不了: 目录下点击[测试80端口]的时候提示:Your port 80 is actually used by : Server: Microsof ...