-
Notifications
You must be signed in to change notification settings - Fork 0
/
125-ValidPalindrome.cpp
38 lines (35 loc) · 1.11 KB
/
125-ValidPalindrome.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
/*=============================================================================
# FileName: 125-ValidPalindrome.cpp
# Desc: AC, 10ms
# Author: Jian Huang
# Email: [email protected]
# HomePage: https://cn.linkedin.com/in/huangjian1993
# Version: 0.0.1
# LastChange: 2015-08-28 22:05:00
# History:
=============================================================================*/
#include <leetcode.h>
class Solution {
public:
bool isPalindrome(string s) {
if (s == "") {
return true;
}
transform(s.begin(), s.end(), s.begin(), ::tolower);
int len = (int)s.length();
string tmp = "";
for (auto c : s) {
if ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')) {
tmp += c;
}
}
len = (int) tmp.length();
int i = 0, j = len - 1;
while (i < j) {
if (tmp[i ++] != tmp[j --]) {
return false;
}
}
return true;
}
};