Leetcode 125 Valid Palindrome 字符串处理
题意:判断字符串是否是回文字符串
先将所有的字母和数字字符保留,并将大写字母转化成小写字母,然后将字符串倒置,比较前后两个字符串是否相同。
该题最好的解法可以模仿 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 字符串处理的更多相关文章
- [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(有效回文)(*)
翻译 给定一个字符串.确定它是否是回文的,仅仅考虑当中的数字和字符并忽略其它. 比如. "A man, a plan, a canal: Panama" 是回文的. "r ...
- LeetCode 125. Valid Palindrome
这个题目只要注意大小写问题即可解决,而且我们只关注的是字母和数值 Given a string, determine if it is a palindrome, considering only a ...
- [leetcode]125. Valid Palindrome判断回文串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- 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 ...
随机推荐
- phpexcel相关函数
1.header [php] header("Content-Type:application/vnd.ms-excel"); header("Content-Dispo ...
- 使用Coookie实现浏览器显示上次的登录时间
实现的效果: 每一次刷新 都会显示上一次访问servlet的时间 ,只适用于同一个浏览器 ,更换浏览器再次访问就该使用session技术了, 因为cookie是浏览器端技术,cookie保存在浏览器 ...
- sql server 2000通过机器名可以连,通过ip连不上的问题
客户那边两台服务器A和B,之前一直都是好好的,今天因为换了网络环境,结果数据库之间不能相互访问了. 目前只能A访问B,B访问不了A,在服务器A上面试了,通过ip连本机,也是连接超时. 开始想着是服务器 ...
- Web开发中的主要概念
一.Web开发中的主要概念1.静态资源:一成不变的.html.js.css2.动态资源:JavaWeb.输出或产生静态资源.(用户用浏览器看到的页面永远都是静态资源) 3.JavaEE:十三种技术的集 ...
- 关于e^PI>PI^e
- 转:dashboard的简明教程
在网上看到一篇不错的dashboard入门blog,在此就不在copy,贴地址: http://www.open-open.com/lib/view/open1389792987430.html 可以 ...
- [Leetcode][JAVA] Best Time to Buy and Sell Stock I, II, III
Best Time to Buy and Sell Stock Say you have an array for which the ith element is the price of a gi ...
- 对于C++窗口编译一闪而过的解决方法 (DEV CPP下)
对于C++窗口编译一闪而过的解决方法 首先来看一个简单的程序(编译环境为 DEV C++.): #include <iostream> int main() { std:: ...
- codeforces 429D
题意:给定一个数组你个数的数组a,定义sum(i, j)表示sigma(a[i],...a[j]),以及另外一个函数f(i, j) = (i - j)^2 + sum(i+1, j)^2 求最小的f( ...
- [leetcode 226] Invert Tree
1 题目: Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 2 思路: 这是因为谷歌面试xx而 ...