Skip to content

Commit bfe9a6a

Browse files
committed
solve: valid-palindrome [week3]
1 parent ac03a8d commit bfe9a6a

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

valid-palindrome/mkwkw.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,35 @@
1-
//set-up
1+
class Solution {
2+
public:
3+
bool isPalindrome(string s) {
4+
5+
string str = "";
6+
7+
for(int i=0; i<s.length(); i++)
8+
{
9+
if(isalpha(s[i]))
10+
{
11+
str += tolower(s[i]);
12+
}
13+
else if (s[i]>='0' && s[i]<='9') //alpha"numeric"
14+
{
15+
str += s[i];
16+
}
17+
}
18+
19+
//Palindrome
20+
if(s.length()==0 || s.length()==1)
21+
{
22+
return true;
23+
}
24+
25+
for(int i=0; i<str.length()/2; i++)
26+
{
27+
if(str[i]!=str[str.length()-1-i])
28+
{
29+
return false;
30+
}
31+
}
32+
33+
return true;
34+
}
35+
};

0 commit comments

Comments
 (0)