125. Valid Palindrome
来源:互联网 发布:java三大框架简述 编辑:程序博客网 时间:2024/06/16 19:30
/*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.两个指针问题*/#include <iostream>#include <string>using namespace std;class Solution {public: bool isPalindrome(string s) { int left=0,right=s.size()-1; while(left<right) { while(left<right && isalnum(s[left]) == false) left++; while(left<right && isalnum(s[right]) == false ) right--; if(left>=right) return true; if(toupper(s[left]) != toupper(s[right])) return false; left++,right--; } return true; }};int main(){ Solution mys; string s="canal: Panama"; cout<<mys.isPalindrome(s)<<endl; return 0;}
阅读全文
0 0
- [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
- 125. Valid Palindrome
- 125. Valid Palindrome LeetCode
- 125. Valid Palindrome
- 【LeetCode】125. Valid Palindrome
- 125. Valid Palindrome
- 125. Valid Palindrome
- Leetcode 125. Valid Palindrome
- LeetCode 125. Valid Palindrome
- LeetCode 125. Valid Palindrome
- LeetCode *** 125. Valid Palindrome
- 对str!=null &&str!="" 项目中的场景——对空值和空串的升级版,还有空白字符等等。
- spring boot 共享session redis实现
- 一元多项式的乘法运算(C语言)实现
- C# 字段与属性区别
- jackson 实体转json属性为NULL或者为空不参加序列化
- 125. Valid Palindrome
- 数据库的基本操作:索引、视图、导入和导出、备份和恢复
- easyUI datagrid(“load”,json 数据)
- vim快捷键
- C#基础-037 里氏转换
- markdown转pdf
- Using Different Versions of R
- C#基础-038 装箱与拆箱
- Spring框架优点