【题解】【字符串】【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 ...
随机推荐
- oracle查锁表SQL
SELECT l.session_id sid, s.serial#, l.locked_mode, l.oracle_username, s.user#, l.os_user_name,s.mach ...
- ACTIVITI 表结构数据分析
ACTIVITI ACT_RU_EXECUTION 表 这个表是工作流程的核心表,流程的驱动都和合格表有密切的关系. 一般来讲一个流程实例都有一条主线.如果流程为直线流程,那么流程实例在这个表 ...
- Learn clojure in Y minutes
Learn X in Y minutes Where X=clojure Get the code: learnclojure.clj Clojure is a Lisp family languag ...
- bzoj3594: [Scoi2014]方伯伯的玉米田
dp新优化姿势... 首先,当我们拔高时,一定右端点是n最优.因为如果右端点是r,相当于降低了r之后玉米的高度.显然n更优. 那么可以dp.dp[i][j]表示前i个拔高j次的LIS.dp[i][j] ...
- Hduacm—5497
#include <cstring> #include <cstdio> #include <iostream> using namespace std; type ...
- 保护WIFI无线网络的安全
本篇博客属于我们隐私与安全小贴士系列博客的一部分,其目的是确保您以及您的家人的上网安全.隐私与安全问题无论对我们还是对您都至关重要.我们在“不可 不知的小知识”网站上为您提供了如何安全,便捷地使用互联 ...
- Java longTime 和C#日期转换
封装一下,可直接用. 以后碰到java的long time,直接使用DateTime dt=ConvertJavaDateTimeToNetTime(1207969641193);这样使用即可. 这串 ...
- Hibernate中的继承映射
1.继承映射 继承映射分为两种情况:简单继承映射和继承映射. 在简单继承映射中,每个子类都要写一个映射文件. 在继承映射中,只使用一个映射文件.继承映射分为三种情况: 所有子类映射到一张表 需要使用鉴 ...
- IE11无法 登陆银行网站
1,打开IE11,看着键盘,按住Alt+X,然后按字母O打开IE设置选项=>[安全]选项卡把安全级别拉到最下,关闭[启用保护模式] 2,点击[受信任的站点]将支付宝和农业银行网址添加进去,关闭选 ...
- JAVA每日一旅3
1.关于byte byte在内存中占一个字节,范围是-128-127,128作强制类型转换到byte变成-128,因为128的二进制表示:1000 0000,最高位是符号位. 2.关于Hibernat ...