【题解】【字符串】【Leetcode】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.
思路:
这题不能更简单了,考察的是徒手写bug的能力= =
代码:
bool isPalindrome(string s) {
int n = s.length();
int i = ;
int j = n-;
while(i<j){//while(i>j){//蠢哭了
while(!isalnum(s[i]) && i<n) i++;//没加i<n会超时,不看题用isalpha()
while(!isalnum(s[j]) && j>=) j--;
if(i<j && tolower(s[i++]) != tolower(s[j--])) //if(s[i++] != s[j--] && i>j)//自加自减最坑了, 不看题没用tolower()
return false;
}
return true;
}
【题解】【字符串】【Leetcode】Valid Palindrome的更多相关文章
- [LeetCode] Valid Palindrome 验证回文字符串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- [LeetCode] Valid Palindrome II 验证回文字符串之二
Given a non-empty string s, you may delete at most one character. Judge whether you can make it a pa ...
- leetcode Valid Palindrome C++&python 题解
题目描写叙述 Given a string, determine if it is a palindrome, considering only alphanumeric characters and ...
- LeetCode之“字符串”:Valid Palindrome
题目链接 题目要求: Given a string, determine if it is a palindrome, considering only alphanumeric characters ...
- LeetCode——Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- LeetCode Valid Palindrome II
原题链接在这里:https://leetcode.com/problems/valid-palindrome-ii/description/ 题目: Given a non-empty string ...
- LeetCode: Valid Palindrome [125]
[题目] Given a string, determine if it is a palindrome, considering only alphanumeric characters and i ...
- [leetcode]Valid Palindrome @ Python
原题地址:https://oj.leetcode.com/problems/valid-palindrome/ 题意: Given a string, determine if it is a pal ...
- [Leetcode] valid palindrome 验证回文
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- Leetcode Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
随机推荐
- iBatisSQL中prepend的问题
是前向声明还是后向声明? 官方文档那个给出:“the overridable SQL part that will be prepended to the statement”.可见是前向声明. -- ...
- linux copy
cp -ri 131115-6/* /web/www/attachment/ 把13这个文件夹下面所有的文件和文件夹复制到 /web/www/attachment cp -a a /web/ww ...
- jdk和tomcat环境部署
部署前需要准备的东西: 1.确定操作系统(32位或64位) 2.准备对应的jdk和tomcat软件 3.准备一份环境变量配置说明,省的到时候忘记了 步骤: 1.安装JDK 安装好JDK后,再配置JDK ...
- MyEclipse10.X 的破解过程详细图解
http://wenku.baidu.com/view/423e95056c85ec3a87c2c512.html
- Hadoop Hello World
Hadoop单机环境配置OK后,需要找个例子测试一下Mapreduce功能.因此从Hadoop源代码中找到一个例子:WordCount.java,来验证. 编译过程如下: cd hadoop-exam ...
- PHP慢脚本日志和Mysql的慢查询日志(转)
1.PHP慢脚本日志 间歇性的502,是后端 PHP-FPM 不可用造成的,间歇性的502一般认为是由于 PHP-FPM 进程重启造成的. 在 PHP-FPM 的子进程数目超过的配置中的数量时候, ...
- poj题目必做
OJ上的一些水题(可用来练手和增加自信) (poj3299T,poj2159T,poj2739T,poj1083T,poj2262T,poj1503T,poj3006T,poj2255T,poj309 ...
- No suitable driver found for jdbc:mysql://localhost/dbname
把mysql-connector-java的jar包放入jdk/jre/lib/ext文件下
- source 命令与“ . ”点命令
http://wenku.baidu.com/link?url=r3_WjJwQziv5wooIiatYbIMotPHcop56ZyakNGFor5DgJLQD-orAwVmOwp80RAnJ3tRD ...
- SharePoint 2013 企业搜索架构示例
博客地址:http://blog.csdn.net/FoxDave 本文参考自微软官方的Chart,我们来看一下企业中对于不同规模SharePoint搜索的场的架构是什么样的. 对于搜索场的规模, ...