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

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

该题最好的解法可以模仿 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. Android体系结构及activity生命周期

    Android的系统架构采用了分层架构的思想,如图1所示.从上层到底层共包括四层,分别是应用程序程序层.应用框架层.系统库和Android运行时和Linux内核 Android的系统架构图    每层 ...

  2. Tcp之异常

    Tcp异常 昨研发报异常,据CMCC说是我方服务器主动断开的,于是怀疑是超时设置过短,于是我抓包,由于我接触socket时日尚短,搞不清为什么三次握手成功之后我方服务器会立刻发送fin 今天本来做实验 ...

  3. nil、Nil、NULL和NSNull的区别和联系

    一.nil 我们给对象赋值时一般会使用object = nil,表示我想把这个对象释放掉: 或者对象由于某种原因,经过多次release,于是对象引用计数器为0了,系统将这块内存释放掉,这个时候这个对 ...

  4. centos下 redis安装配置及简单测试

    1:安装redis(使用的的环境是centos6.7 redis-2.6.14) 将redis-2.6.14.tar.gz文件拷贝到/usr/local/src 目录下 解压文件  tar zxvf ...

  5. JavaScript-join连接符

    1.转字符串:2种 1.将数组中每个元素都转为字符串,再用逗号分隔:var str=String(arr); 2.将数组中每个元素都字符串,再用自定义下标连接每个元素 var str=arr.join ...

  6. spring:bean的定义

    一个完整的Bean的配置文件: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE beans ...

  7. (转) 在C#用HttpWebRequest中发送GET/HTTP/HTTPS请求

    转自:http://blog.csdn.net/zhoufoxcn/article/details/6404236 通用辅助类 下面是我编写的一个辅助类,在这个类中采用了HttpWebRequest中 ...

  8. border-radius(边框半径)

    可以使用像素来指定border-radius的属性值使角变圆 除了像素,你还可以使用百分比来指定border-radius边框半径的值

  9. First Blog, “Hello, world!”

    As every single book says as a tradition, "Hello, world!" An explanation about the name – ...

  10. web标准:img图片在ie6下显示空白的bug解决方案

    在进行页面的DIV+CSS排版时,遇到IE6(当然有时Firefox下也会偶遇)浏览器中的图片元素img下出现多余空白的问题绝对是常见的对于该问题的解决方法也是“见机行事”. 1.将图片转换为块级对象 ...