[Leetcode] 125. Valid Palindrome 解题报告
来源:互联网 发布:linux suspend 命令 编辑:程序博客网 时间:2024/06/08 17:42
题目:
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.
思路:
这是一道名副其实的水题。然而如果了解了STL中的库函数之后,会让你写起来更得心应手。这里总结几个STL中的相关函数吧:
int isdigit(int c): check if a character is decimal digit. Decimal digits are any of: 0 1 2 3 4 5 6 7 8 9
int isalpha(int c): check if a character is alphabetic. Checks whether c is an alphabetic letter, either uppercase or lowercase.
int isalnum(int c): check if a character is alphanumeric. Checks whether c is either a decimal digit or an uppercase or lowercase letter.
代码:
class Solution {public: bool isPalindrome(string s) { int length = s.length(); int left = 0, right = s.size() - 1; while (left < right) { while (left < right && !isalnum(s[left])) { ++left; } while (left < right && !isalnum(s[right])) { --right; } if (left < right && tolower(s[left++]) != tolower(s[right--])) { return false; } } return true; }};
- [leetcode] 125. Valid Palindrome 解题报告
- [Leetcode] 125. Valid Palindrome 解题报告
- [leetcode]125. Valid Palindrome@Java解题报告
- Leetcode 125. Valid Palindrome 回文验证 解题报告
- [LeetCode]Palindrome Number,解题报告
- [LeetCode]Palindrome Partitioning,解题报告
- 【LeetCode】Palindrome Partitioning 解题报告
- LeetCode-Shortest Palindrome-解题报告
- LeetCode解题报告--Palindrome Number
- [LeetCode] Palindrome Number 解题报告
- 【LeetCode】Longest Palindrome 解题报告
- [LeetCode] Palindrome Number 解题报告
- 【LeetCode】Palindrome Number 解题报告
- 【LeetCode】Valid Number 解题报告
- LeetCode解题报告--Valid Parentheses
- [LeetCode] Valid Parentheses 解题报告
- [LeetCode] Valid Sudoku 解题报告
- 【LeetCode】Valid Anagram 解题报告
- Python 基础复习
- 用JS操作cookie的一个小插件,挺好用的
- 常用
- Nginx安装和使用
- 几种方法来实现scp拷贝时无需输入密码
- [Leetcode] 125. Valid Palindrome 解题报告
- Xlua使用C#中第三方库:DoTween
- 共享平台逻辑架构设计
- hdu 1754 线段树单点更新求最大值
- 解决js代码中加入alert()就成功执行,不加就不对的问题!
- python—命名规范
- 关于消息队列的使用----ActiveMQ,RabbitMQ,ZeroMQ,Kafka,MetaMQ,RocketMQ
- OSTaskCreateHook(),OSTaskDelHook(),OSTaskSwHook(),OSTaskStatHook(),OSTimeTickHook()
- 云帮社区版4月升级,支持主流Go版本,修复了若干Bug