Palindrome Checker

Palindrome Checker#

Twitter Handle LinkedIn Profile GitHub Profile LeetCode Problem Difficulty

Problem#

Question details can be found here.

Constraints and Assumptions#

Placeholder.

Implementation#

@dataclass(frozen=False, init=True)
class Solution:
    deque: DeQueueList[str] = field(default_factory=DeQueueList)

    def check_palindrome(self, string: str) -> bool:
        for char in string:
            self.deque.add_rear(char)  # enqueue

        while self.deque.size > 1:
            front = self.deque.remove_front()
            rear = self.deque.remove_rear()
            if front != rear:
                return False
        # if deque.size = 1 then it must be true
        return True
str_1 = "radar"
str_2 = "lsdkjfskf"

Solution().check_palindrome(str_1), Solution().check_palindrome(str_2)
(True, False)