LeetCode 125. Valid Palindrome
2016-07-22 01:38
363 查看
125. Valid Palindrome
My Submissions QuestionEditorial Solution
Total Accepted: 99300 Total Submissions: 417275 Difficulty: Easy
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.
My Submissions QuestionEditorial Solution
Total Accepted: 99300 Total Submissions: 417275 Difficulty: Easy
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.
class Solution { public: bool isPalindrome(string s) { if(s.length() == 0) return true; int i = 0, j = s.length() - 1; while(i < j) { while(i < j && !isalnum(s[i])) { i++; } while(i < j && !isalnum(s[j])) { j--; } if(i < j && tolower(s[i]) != tolower(s[j])) { return false; } else { i++; j--; } } return true; } };
相关文章推荐
- LeetCode 6. ZigZag Conversion
- LeetCode 7. Reverse Integer
- Java 批量随机生成身份证号码(未测试)
- LeetCode 278. First Bad Version
- Microsoft SQL Server 自定义函数整理大全(下)
- 简单的java爬虫抓取网页实现代码(未测试)
- LeetCode 34. Search for a Range
- 预编译小常识
- java 汉字转化为拼音工具类(未测试)
- LeetCode 215 Kth Largest Element in an Array
- LeetCode 155. Min Stack
- LeetCode165. Compare Version Numbers
- LeetCode 168. Excel Sheet Column Title
- Freemarker 最简单的例子程序
- JAVA 比较两张图片的相似度的代码(未测试)
- c语言枚举类型
- LeetCode 8. String to Integer (atoi)
- SpringMVC多文件上传实例(未测试)
- LeetCode319. Bulb Switcher
- LeetCode 144. Binary Tree Preorder Traversal