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
Recommended Posts
Gas Station | InterviewBit | Solution Explained
June 13, 2022
Majority Element | InterviewBit | Solution Explained
June 13, 2022
Please write the proof.
This solution need an amendment for 2 digit number.
Please write a Proof for this