나의 발자취
[Two Pointer, ::] 125. Valid Palindrome 본문
문제가 요구하는 것에 따라서 조금씩 다르다. LC에서는 파이썬의 리스트 인덱싱 기법을 이용해서 풀었고,
class Solution:
def isPalindrome(self, s: str) -> bool:
phrase = []
for i in s:
if i.isalnum():
phrase.append(i.lower())
return phrase == phrase[::-1]
다른데에서는 투포인터 이용해서 풀었다.
def is_palindrome(s):
left = 0
right = len(s)-1
while left < right:
if s[left] != s[right]:
return False
else:
left += 1
right -= 1
return True
'알고리즘' 카테고리의 다른 글
[Two Pointers] 19. Remove Nth Node From End of List (0) | 2025.02.13 |
---|---|
[Two Pointers] 15. 3Sum (0) | 2025.02.13 |
Two Pointers 기법이란? (Why / When / How to use) (0) | 2025.02.13 |
334. Increasing Triplet Subsequence (0) | 2025.01.30 |
[그리디] 605. Can Place Flowers (2) | 2025.01.04 |
Comments