문제 링크: leetcode.com/problems/valid-palindrome/
문제 유형:
접근방식:
Palindrome (회문) 개념 - 2020/12/13 - [Algorithnm/ps 개념] - [PS] Palindrome
리스트에 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 |
최근댓글