题意:判断字符串是否是回文字符串

先将所有的字母和数字字符保留,并将大写字母转化成小写字母,然后将字符串倒置,比较前后两个字符串是否相同。

该题最好的解法可以模仿 Leetcode 345 Reverse Vowels of a String 字符串处理

class Solution {
public:
bool isPalindrome(string s) {
string::size_type j = ;
for(string::size_type i = ; i< s.size(); ++i){
if(isalpha(s[i]) || isdigit(s[i])) {
if(isupper(s[i])) s[j++] = s[i] - 'A' + 'a';
else s[j++] = s[i] ;
}
}
string t = s.substr(, j);
string str = t;
reverse(t.begin(),t.end());
return t == str;
}
};

Leetcode 125 Valid Palindrome 字符串处理的更多相关文章

  1. [LeetCode] 125. Valid Palindrome 验证回文字符串

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  2. leetcode 125. Valid Palindrome ----- java

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  3. Java [Leetcode 125]Valid Palindrome

    题目描述: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ...

  4. LeetCode 125 Valid Palindrome(有效回文)(*)

    翻译 给定一个字符串.确定它是否是回文的,仅仅考虑当中的数字和字符并忽略其它. 比如. "A man, a plan, a canal: Panama" 是回文的. "r ...

  5. LeetCode 125. Valid Palindrome

    这个题目只要注意大小写问题即可解决,而且我们只关注的是字母和数值 Given a string, determine if it is a palindrome, considering only a ...

  6. [leetcode]125. Valid Palindrome判断回文串

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  7. Java for LeetCode 125 Valid Palindrome

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  8. [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 ...

  9. 125. Valid Palindrome【easy】

    125. Valid Palindrome[easy] Given a string, determine if it is a palindrome, considering only alphan ...

随机推荐

  1. [原创][LaTex]LaTex学习笔记之框架及宏包

    0. 简介 LaTex在书写文档时的最基本单元就是首部的写作,变相的也可以说是头文件.本文章就来总结一下文档的基本格式和常用宏包. 1. 基本单元 基本单元需要对LaTex语法有一定的了解,这个很简单 ...

  2. [整理]PCB阻抗控制

    之前一直听说PCB设计中信号完整性及阻抗方面的要求,但是本人对此还是有很多的不了解,每次和别人讨论到这里后就不知道该怎么继续就这个问题交谈下去.正巧最近手头有一点工作有这方面的一些需求,就拿来花了一点 ...

  3. Android 环境通过国内映像快速搭建

    Android 环境通过国内映像快速搭建 转眼大半年没有写android程序了,回顾从环境搭建开始. 因为google受国内限制,因此下载android的SDK相当慢,因此寻找国内的镜像进行搭建. 首 ...

  4. Fiddler学习之——对Android应用进行抓包

    Fiddler做为实用的http抓包工具,它的原理是在本机开启了一个http的代理服务器,然后它会转发所有的http请求和响应,因此,它比一般的firebug或者是chrome自带的抓包工具要好用的多 ...

  5. ubuntu14.04 的网络配置

    为eth0 配置网络 vi /etc/network/intefaces 添加以下内容 auto eth0 iface eth0 inet static address 192.168.0.10 ne ...

  6. 基于TP框架的ThinkCMF,控制器display方法源码分析

    昨天在写代码的时候,看见写了无数次的模版渲染方法:$this->display(),突然很想弄清楚它是如何实现的. 今天不忙,就分析了一下. class TestController exten ...

  7. C#事务的使用

    1.引入相应的命名空间 using System.Transactions; 2.代码事例(using (TransactionScope ts = new TransactionScope())) ...

  8. (2015秋) 作业6:(电梯系统之结对编程 I 总分=2*50 分)

    电梯系统 0. 背景 南通大学钟秀校区“主教学楼” 用 2 部电梯(连地下室共9层):每到下课.上课前都特别拥挤,大家希望改进已有的电梯调度算法,满足学生和老师快速乘坐电梯的需要.因此,需要重新设计一 ...

  9. struts2获得请求参数的方式

    1.用Action的属性接收参数 2.用DomainModel(域模型)接收参数 3.用ModelDriven接收参数 使用这种方式接受参数需要实现ModelDriven接口,

  10. PHP创建缩略图造成图片质量低下的完美解决方法

    近期弄个论坛,在首页要有个排名,显示评论最多的前十位用户的列表,列表有个略图是用户最新上传的作品,如果使用原来的图,图片过大,首页加载过慢,因此要使用略图 以上来使用imagecopyresized这 ...