125. Valid Palindrome (Array; Two-Pointers)
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 sLength = s.length();
int front = -;
int rear = sLength;
char cFront;
char cRear;
while ()
{
cFront = s[++front];
cRear = s[--rear];
if(front > rear) break;
if(cFront <= 'Z'&& cFront >='A')
{
cFront +=;
}
if(cRear <= 'Z'&& cRear >='A')
{
cRear +=;
}
while( cFront < '' || (cFront < 'a' && cFront > '')|| cFront>'z')
{
cFront = s[++front];
if(front >= rear) break;
if(cFront <= 'Z'&& cFront >='A')
{
cFront +=;
}
}
while( cRear < '' || (cRear < 'a' && cRear > '')|| cRear>'z')
{
cRear = s[--rear];
if(front >= rear) break;
if(cRear <= 'Z'&& cRear >='A')
{
cRear +=;
}
}
if(front >= rear) break;
if(cFront!=cRear)
{
return false;
}
}
return true;
}
};
125. Valid Palindrome (Array; Two-Pointers)的更多相关文章
- 125. Valid Palindrome【easy】
125. Valid Palindrome[easy] Given a string, determine if it is a palindrome, considering only alphan ...
- [LeetCode]题解(python):125 Valid Palindrome
题目来源 https://leetcode.com/problems/valid-palindrome/ Given a string, determine if it is a palindrome ...
- 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 [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 ig ...
- 【一天一道LeetCode】#125. Valid Palindrome
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- [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 ...
随机推荐
- sailsjs 不用写代码就能生成rest api 代码
1. 脚手架安装 npm install sails -g 2. 生成基本项目 a. 项目 sails new appdemo b. 创建api sails new api demoapi a ...
- php基础语法(文件加载和错误)
文件加载 有4个文件加载的语法形式(注意,不是函数): include, include_once, require, require_once; 他们的本质是一样的,都是用于加载/引入/包含/载 ...
- DZ X3 和 ECshop 通过uc_server实现会员同步整合教程.
会员数据整合是实现商城和论坛系统共享会员数据.论坛系统注册会员整合后可直接在商城登陆.现以本人社区为例.本人社区采用DZ最新的X3.1 商城采用的ECshop最近的V2.7.3 现在想把两个模板整合在 ...
- 初始化Lights Out 100(ilo100)密码
初始化Lights Out 100(ilo100)密码 /HP ProLiant General /HP Software /初始化Lights Out 100(ilo100)密码 2014年5月21 ...
- java的try-with-resource机制
在java7之后可以使用try(resource1, resource2){...}这样声明之后,在try{}执行完成之后或者抛异常跳出,都会调用reouce1.close(),resource2.c ...
- CMD中文显示为乱码
中文显示为乱码 临时解决方案: 在 CMD 中运行 chcp 936. 永久解决方案: 打开不正常的 CMD 或命令提示符窗口后,单击窗口左上角的图标,选择弹出的菜单中的“默认值”,打开如下图的对话框 ...
- DomHelper
public class DomHelper { public static ArrayList<Person> queryXML(Context context) { ArrayList ...
- Win10 TensorFlow(gpu)安装详解
Win10 TensorFlow(gpu)安装详解 写在前面:TensorFlow是谷歌基于DistBelief进行研发的第二代人工智能学习系统,其命名来源于本身的运行原理.Tensor(张量)意味着 ...
- Java-Runoob:Java 日期时间
ylbtech-Java-Runoob:Java 日期时间 1.返回顶部 1. Java 日期时间 java.util 包提供了 Date 类来封装当前的日期和时间. Date 类提供两个构造函数来实 ...
- 浅谈PHP面向对象编程(八、多态)
8.0 多态 在设计一个成员方法时,通常希望该方法具备一定的通用性.例如要实现一个动物叫的方法,由于每个动物的叫声是不同的,因此可以在方法中接收-个动物类型的参数的对象当传人猫类对象时就发出猫类的叫 ...