[leetcode-125] Palindrome + Slicing
ยท
๐Ÿข 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
[leetcode-125] Palindrome
ยท
๐Ÿข 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' ํƒœ๊ทธ์˜ ๊ธ€ ๋ชฉ๋ก