Soohan-Kim / Leetcode

0 stars 0 forks source link

[HW 4] Valid Palindrome #125. #44

Open Soohan-Kim opened 3 weeks ago

Soohan-Kim commented 3 weeks ago

https://leetcode.com/problems/valid-palindrome/description/

Soohan-Kim commented 3 weeks ago
class Solution:
    def isPalindrome(self, s: str) -> bool:

        new_s = ""
        for c in s:
            if c.isalnum():
                new_s += c.lower()

        l, r = 0, len(new_s)-1

        while l<=r:
            if new_s[l] == new_s[r]:
                l += 1
                r -= 1
            else:
                return False

        return True