Skip to content

Commit 2508b48

Browse files
authored
heozeop: valid palindrome
1 parent 274e467 commit 2508b48

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

valid-palindrome/heozeop.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Time Complexity: O(n)
2+
// Spatial Complexity: O(n)
3+
4+
class Solution {
5+
public:
6+
bool isPalindrome(string s) {
7+
string temp = "";
8+
for(char c : s) {
9+
if(isalnum(c)) {
10+
temp += tolower(c);
11+
}
12+
}
13+
14+
int length = temp.length();
15+
for(int i = 0; i < length / 2; ++i) {
16+
if(temp[i] != temp[length - 1 - i]) {
17+
return false;
18+
}
19+
}
20+
21+
return true;
22+
}
23+
};

0 commit comments

Comments
 (0)