Palindrome

· One step
using Slicing leetcode-125 + 정규식 사용import re import collections class Solution: def isPalindrome(self, s: str) -> bool: s = s.lower() s = re.sub('[^a-z0-9]','',s) return s == s[::-1] # reverse Result : 46ms Memory: 15.7mb
· One step
LeetCode 125 Valid Palindrome Palindrome : 대소문자 구분 없이 좌우가 대칭인 문자열 1. isalnum : 문자 판별 후 소문자 변환 test = 'is a car ; rac a si' c_string = [] for s in test: if s.isalnum(): # 문자인지 판별 c_string.append(s.lower()) # 소문자로 변환 # c_string # ['i', 's', 'a', 'c', 'a', 'r', 'r', 'a', 'c', 'a', 's', 'i'] 2. loop로 첫번째 마지막 문자열 비교 후 pop while len(c_string) > 1: if c_string.pop(0) != c_string.pop(): break #c_string ..
다했다
'Palindrome' 태그의 글 목록