-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path125.验证回文串.cpp
68 lines (61 loc) · 1.54 KB
/
125.验证回文串.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* @lc app=leetcode.cn id=125 lang=cpp
*
* [125] 验证回文串
*/
// @lc code=start
#include<iostream>
#include<string>
using namespace std;
class Solution {
public:
bool isPalindrome(string s) {
string sgood;
for(char ch:s)
{
if(isalnum(ch))
{
sgood+=tolower(ch);
}
}
string sgood_rev(sgood.rbegin(),sgood.rend());
return sgood==sgood_rev;
}
// bool isPalindrome(string s) {
// auto i=s.begin(),j=s.end()-1;
// while(i<j){
// if(isalpha(*i)||isdigit(*i)){
// if(isalpha(*i)){
// *i = tolower(*i);
// }
// }else{
// ++i;
// }
// if(isalpha(*j)||isdigit(*j)){
// if(isalpha(*j)){
// *j = tolower(*j);
// }
// }else{
// --j;
// }
// if((isalpha(*i)||isdigit(*i))&&(isalpha(*j)||isdigit(*j))){
// if(isalpha(*i)){
// *i = tolower(*i);
// }
// if(isalpha(*j)){
// *j = tolower(*j);
// }
// if(*i!=*j)
// {
// cout<<*i<<endl;
// cout<<*j<<endl;
// return false;
// }
// ++i;
// --j;
// }
// }
// return true;
// }
};
// @lc code=end