Valid Palindrome
A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.
Given a string s, return true if it is a palindrome, or false otherwise.
Example 1:
Input: s = "A man, a plan, a canal: Panama"
Output: true
Explanation: "amanaplanacanalpanama" is a palindrome.
Constraints:
1 <= s.length <= 2 * 105
s consists only of printable ASCII characters.
문제의 내용은 대문자 등 소문자등 상관없이
앞으로 읽든 뒤로 읽든 같으면 true 틀리면 false 를 출력하는 함수를 만들라는것이다. 단 입력은 길이 2*105 만큼 아스키 문자 어떤것이든 온다
from collections import deque
class Solution:
def isPalindrome(self, s: str) -> bool:
char_que = deque()
for el in s:
if el.isalnum():
char_que.append(el.lower())
len_que = len(char_que)
for _ in range(len_que//2):
if char_que.pop() != char_que.popleft():
return False
return True