3.1—字符串—Valid Palindrome
来源:互联网 发布:淘宝菜鸟驿站 编辑:程序博客网 时间:2024/05/17 09:08
描述
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? is is a good question to ask during an
interview.
For the purpose of this problem, we define empty string as 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? is 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>#include<cmath>using namespace std;bool IsPalindrome(string str){if (str == "")return false;int begin = 0;int end = str.size() - 1;while (begin <= end){while (!(('a' <= str[begin] && str[begin] <= 'z') || ('A' <= str[begin] && str[begin] <= 'Z')))begin++;while (!(('a' <= str[end] && str[end] <= 'z') || ('A' <= str[end] && str[end] <= 'Z')))end--;if ((str[begin] == str[end]) || (abs(str[begin] - str[end]) == 32)){begin++;end--;}else{return false;}}return true;}int main(){string str = "A man ,a plan,a canal:Panama";bool flag = IsPalindrome(str);if (flag)cout << str << "是回文!" << endl;}
阅读全文
0 0
- 3.1—字符串—Valid Palindrome
- LeetCode125—Valid Palindrome
- 【字符串回文】Valid Palindrome
- Leetcode 字符串 Valid Palindrome
- Valid Palindrome(回文字符串)
- LeetCode——Valid Palindrome
- LeetCode125——Valid Palindrome
- LeetCode——Valid Palindrome
- Algorithms—125.Valid Palindrome
- leetcode:字符串之Valid Palindrome && Palindrome Number
- Valid Palindrome 判断回文字符串
- leetcode125---Valid Palindrome(回文字符串)
- [leetcoide] 【字符串】125. Valid Palindrome
- leetcode 第三章字符串--3.1 valid palindrome--2017/7/26
- 3.1 Valid Palindrome
- 【leetcode】3.1 valid palindrome
- Leecode记录——Valid Palindrome
- leetcode 125 —— Valid Palindrome
- java搬运工——IO流
- SQL练习(一)
- Liux查看日志的简单方法
- 容斥原理(组合数学)总结
- 2.2Android调研
- 3.1—字符串—Valid Palindrome
- leetcode 513. Find Bottom Left Tree Value
- node
- [自用]门户网站模板-招标公告
- java SE总结
- AI将带我们去何方?(下-展望篇)
- 解读STM32单片机:代码实现 PCROP清除
- innerHTML与innerText区别
- JAVA反射获得属性及简单应用