Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions C++/125_Valid_Palindrome.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//125. 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.

Author: Xinyu Liu
*/

#include <string>
using namespace std;

class Solution {
public:
bool isPalindrome(string s) {
string::iterator start = s.begin();
string::iterator end = s.end() - 1;
while(start < end){
while (start < end && !isalnum(*start))
start ++;
while (start < end && !isalnum(*end))
end --;
if (tolower(*start )!= tolower(*end))
return false;
start ++;
end--;
}
return true;

}
};

void main(){
string str_test = "test";
Solution sol;
bool bol = sol.isPalindrome(str_test);
}