Quick actions

cmd+k|ctrl+k

Navigation

Languages

isPalindrome

Snippet info

Language

Python

Visibility

public

Author

soham57

Created

2022-09-04T07:43:26.931254Z

Updated

2022-09-04T07:43:26.931254Z

# INPUT: String
# OUTPUT: Boolean
def isPalindrome(s):

        #starting from 0
        i = 0
        #starting from end of string
        j = len(s)-1
        
        while i < j:
            #ignoring whitespaces and special characters
            while not s[i].isalnum() and i < j:
                i+=1
            while not s[j].isalnum() and i < j: 
                j-=1
            
            #Checking for equility
            if s[i].lower() == s[j].lower():
                i+=1
                j-=1
            else:
                return False
        return True
#
# SC: O(1)
# TC: O(N)

print(isPalindrome("Tooo ot"))
INFO