[leetcoide] 【字符串】125. Valid Palindrome
来源:互联网 发布:儿童机器人编程入门 编辑:程序博客网 时间:2024/06/01 16: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.
题意
判断一个字符串是否是回文字符串,只考虑字母数字。
比如"A man, a plan, a canal: Panama"是回文;
"race a car"
不是回文。 空字符串也是回文。题解
两个指针分别指向头和尾,注意只考虑字母数字,所以需要过滤。我这里自己写了过滤函数,c++里面也有专门的
::
isalnum
(*left)
然后向中间夹逼即可。
class Solution {public: bool isalpahanumeric(char c) { if((c>='0'&&c<='9')||(c>='a'&&c<='z')) return true; else return false; } bool isPalindrome(string s) { transform(s.begin(),s.end(),s.begin(),::tolower); auto left=s.begin(),right=prev(s.end()); while(left<right) { if(!isalpahanumeric(*left)) left++; else if(!isalpahanumeric(*right)) right--; else if(*left!=*right) return false; else { left++; right--; } } return true; }};
0 0
- [leetcoide] 【字符串】125. Valid Palindrome
- 125. Valid Palindrome (回文字符串判断)
- 【字符串回文】Valid Palindrome
- Leetcode 字符串 Valid Palindrome
- Valid Palindrome(回文字符串)
- [leetcoide] 【字符串】28. Implement strStr()
- leetcode:字符串之Valid Palindrome && Palindrome Number
- Valid Palindrome 判断回文字符串
- leetcode125---Valid Palindrome(回文字符串)
- <LeetCode>125.Valid Palindrome 验证回文字符串 Tag:string
- [LeetCode]125.Valid Palindrome
- LeetCode 125. Valid Palindrome
- [Leetcode] 125. Valid Palindrome
- 【LeetCode】125.Valid Palindrome
- [leetcode] 125.Valid Palindrome
- 125. Valid Palindrome
- [leetcode] 125.Valid Palindrome
- Leetcode 125. Valid Palindrome
- MySQL BTree【index type】 原理
- 2016山东省第七届acm省赛 G题Triple Nim
- Java排序算法总结
- 使用.net(C#)发送邮件(带成功案例)
- word2vector学习笔记(一)
- [leetcoide] 【字符串】125. Valid Palindrome
- Android 屏幕截屏
- 银联则及终端iso8583报文规范的理解
- 解决“com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536”问题
- MATLAB 画颜色网格图
- Android---乐学成语
- 设计模式(3)——单例模式
- L1-002 打印沙漏
- 梳理spring-总结篇