Skip to content

Commit

Permalink
heozeop: valid palindrome
Browse files Browse the repository at this point in the history
  • Loading branch information
heozeop authored Sep 1, 2024
1 parent 274e467 commit 2508b48
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions valid-palindrome/heozeop.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Time Complexity: O(n)
// Spatial Complexity: O(n)

class Solution {
public:
bool isPalindrome(string s) {
string temp = "";
for(char c : s) {
if(isalnum(c)) {
temp += tolower(c);
}
}

int length = temp.length();
for(int i = 0; i < length / 2; ++i) {
if(temp[i] != temp[length - 1 - i]) {
return false;
}
}

return true;
}
};

0 comments on commit 2508b48

Please sign in to comment.