From 2508b4824805e151a1e0ced575bacddc9c111e6c Mon Sep 17 00:00:00 2001 From: Lee seung chan Date: Sun, 1 Sep 2024 15:34:02 +0900 Subject: [PATCH] heozeop: valid palindrome --- valid-palindrome/heozeop.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 valid-palindrome/heozeop.cpp diff --git a/valid-palindrome/heozeop.cpp b/valid-palindrome/heozeop.cpp new file mode 100644 index 000000000..30b6b42f4 --- /dev/null +++ b/valid-palindrome/heozeop.cpp @@ -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; + } +};