문제 링크: leetcode.com/problems/valid-palindrome/
Valid Palindrome - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
문제 유형:

접근방식:
Palindrome (회문) 개념 - 2020/12/13 - [Algorithnm/ps 개념] - [PS] Palindrome
[PS] Palindrome
팰린드롬은 한국어로 '회문'이라고 번역된다. ex) 'eye' , 'madam' 한국어 팰린드롬 ex) '다시 합시다', '다시 합창 합시다', '소주 만병만 주소' 팰린드롬 정의: 거꾸로 읽어도 제대로 읽는 것과 같은 문
parase.tistory.com
리스트에 string들을 집어넣고 첫 번째 인덱스와 마지막 인덱스를 비교해보았습니다.
코드:
Python3
class Solution:
def isPalindrome(self, s: str) -> bool:
nums = []
for i in s:
if i.isalnum():
nums.append(i.lower())
while len(nums) > 1:
if nums.pop(0) != nums.pop():
return False
return True
코드 참고 글:
2020/12/13 - [Python3] - [Python3][Method] pop() 메소드 및 자료구조
2020/12/13 - [Python3] - [Python3][Method] 파이썬3 isalnum(),isalpha() 메소드
'Algorithnm > LeetCode' 카테고리의 다른 글
[LeetCode]54번 : Spiral Matrix (0) | 2021.02.24 |
---|---|
[LeetCode]172번 : Factorial Trailing Zeroes (0) | 2020.12.18 |
최근댓글