Valid Palindrome String | LeetCode | InterviewBit | Solution

LeetCode Problem Link. InterviewBit Problem Link.

class Solution:
    def isPalindrome(self, s):
        ns = ""
        for c in s.lower():
            c = c
            if 'a' <= c <= 'z' or '0' <= c <= '9':
                ns += c
        return int(ns == ns[::-1])
class Solution:
    def isPalindrome(self, s: str) -> bool:
        l, r = 0, len(s)-1
        s = s.lower()
        while l < r:
            if s[l] == s[r]:
                l += 1
                r -= 1
            elif not ('a' <= s[l] <= 'z' or '0' <= s[l] <= '9'):
                l += 1
            elif not ('a' <= s[r] <= 'z' or '0' <= s[r] <= '9'):
                r -= 1
            else:
                return False
        return True
Avatar for Tanishq Chaudhary

Producing high-quality intuitive explanations of interview problems. Currently covering LeetCode and InterviewBit.

    Comments

    1. Please write the proof.

    2. This solution need an amendment for 2 digit number.

    3. Please write a Proof for this

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.