-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path125.valid-palindrome.cpp
More file actions
39 lines (34 loc) · 885 Bytes
/
125.valid-palindrome.cpp
File metadata and controls
39 lines (34 loc) · 885 Bytes
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
/*
* @lc app=leetcode id=125 lang=cpp
*
* [125] Valid Palindrome
*/
// @lc code=start
class Solution {
public:
bool isPalindrome(string s) {
int start = 0;
int end = s.length() - 1;
while (start <= end) {
if(s[start] >= 'A' && s[start] <= 'Z'){
s[start]=s[start]+32;
}
if(s[end] >= 'A' && s[end] <= 'Z'){
s[end]=s[end]+32;
}
if ((s[start] < 'a' || s[start] > 'z') && (s[start] < 48 || s[start] > 57)) {
start++;
continue;
}
if ((s[end] < 'a' || s[end] > 'z') && (s[end] < 48 || s[end] > 57 )) {
end--;
continue;
}
if (s[start++] != s[end--]) {
return false;
}
}
return true;
}
};
// @lc code=end