LeetCode 125. 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 start = , end = s.size() - ;
while (start < end)
{
if ('a' <= s[start] && s[start] <= 'z' || 'A' <= s[start] && s[start] <= 'Z' ||
'' <= s[start] && s[start] <= '')
{
bool tag = true;
while (tag)
{
if ('a' <= s[end] && s[end] <= 'z' || 'A' <= s[end] && s[end] <= 'Z' ||
'' <= s[end] && s[end] <= '')
{
if (s[start] == s[end]||s[start]==toupper(s[end])||s[start]==tolower(s[end]))
{
++start;
--end;
tag = false;
}
else
{
return false;
}
}
else
{
--end;
tag = true;
}
}
}
else
++start;
}
return true;
}
};
LeetCode 125. Valid Palindrome的更多相关文章
- [LeetCode] 125. 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 ...
- Java [Leetcode 125]Valid Palindrome
题目描述: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ...
- [leetcode]125. Valid Palindrome判断回文串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- LeetCode 125 Valid Palindrome(有效回文)(*)
翻译 给定一个字符串.确定它是否是回文的,仅仅考虑当中的数字和字符并忽略其它. 比如. "A man, a plan, a canal: Panama" 是回文的. "r ...
- Leetcode 125 Valid Palindrome 字符串处理
题意:判断字符串是否是回文字符串 先将所有的字母和数字字符保留,并将大写字母转化成小写字母,然后将字符串倒置,比较前后两个字符串是否相同. 该题最好的解法可以模仿 Leetcode 345 Rever ...
- Java for LeetCode 125 Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- [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 ...
- 125. Valid Palindrome【easy】
125. Valid Palindrome[easy] Given a string, determine if it is a palindrome, considering only alphan ...
随机推荐
- C语言常用的小代码
圆周率Pi tan(Pi/4)=1 => Pi=4*arctan(1) 反正切函数arctan()在C语言里表示为atan(),为保证精度取圆周率的代码如下: const double Pi = ...
- Android 隐藏Fragment
1.隐藏Fragment FragmentManager fManager = getFragmentManager(); fManager.beginTransaction() .setCustom ...
- HTML5 CANVAS 高级
加载图片 获取图像有三种方式: a : createImageData(),没有效率,一个像素一个像素的绘制: b : var img= document.getElementById("i ...
- php 查询出来的字段名全是小写或者大写
PHP PDO预定义常量 PDO::CASE_LOWER -- 强制列名是小写PDO::CASE_NATURAL -- 列名按照原始的方式PDO::CASE_UPPER -- 强制列名为大写 修改此参 ...
- Nginx实现内参:为什么架构很重要?
Nginx在web开发者眼中就是高并发高性能的代名词,其基于事件的架构也被众多开发者效仿.我从Nginx的网站找到一篇技术文章将Nginx是怎样实现的,文章是Nginx的产品老大Owen Garret ...
- (MVVM) button enable 时,UI没有被刷新。
if (!this.CanExecuteSubmitButton) { this.CanExecuteSubmitButton = true; CommandManager.InvalidateReq ...
- (C#) 设定时间格式
private string GetCurrentDateTime() { return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") ...
- [Java Web – Maven – 1A]maven 3.3.3 for windows 配置(转)
1.环境 系统环境:windows 2008 R2 JDK VERSION: 1.7.0_10 2.下载地址 MAVEN 下载地址:http://maven.apache.org/download.c ...
- SQL语言的三个分类:DDL、DML、DCL
DML:数据操纵语言,主要是完成数据的新增,修改,删除和查询的操作. DDL:数据定义语言,主要是用来创建或修改表.视图.存储过程以及用户等. DCL:数据控制语言,是用来设置或更改数据库用户或角色权 ...
- JVM 类型的生命周期学习
Java虚拟机通过装载.连接和初始化一个JAVA类型,使该类型可以被正在运行的JAVA程序所使用,其中,装载就是把二进制形式的JAVA类型读入JAVA虚拟机中:而连接就是把这种读入虚拟机的二进制形式的 ...