floatFirstTOC: right
๐ฅ๏ธย ์์ํ๋ฉฐ
์ฃผ์ด์ง ์ฐ๊ฒฐ ๋ฆฌ์คํธ๊ฐ ํฐ๋ฆฐ๋๋กฌ(ํ๋ฌธ)์ธ์ง ํ๋ณํ๋ ๋ฌธ์ ๋ค. ์ฆ, ๋ค์ง์ด๋ ๊ฐ์ ์ฐ๊ฒฐ๋ฆฌ์คํธ๊ฐ ๋๋์ง ํ์ธํ๋ฉด ๋๋ค.
ย
head๊ฐ ๋น์ด์๋ค๋ฉด True๋ก ํ์
- ์ฐ๊ฒฐ ๋ฆฌ์คํธ๋ฅผ ์ํํ๋ฉด์ deque์ ๋ฃ์ ํ, ์์ชฝ ๋์ ์๋ก ํ๋ณ
for i in range(length // 2): if queue[i] != queue[length - 1 - i]: return False
ย
โ๏ธย Python
from collections import deque class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next class Solution: def isPalindrome(self, head: ListNode) -> bool: if not head: # head๊ฐ ๋น์ด์๋ค๋ฉด return True queue = deque() # head๊ฐ ๋น ๋๊น์ง queue์ ์ฝ์ while head is not None: queue.append(head.val) head = head.next # ์์ชฝ ๋์ผ๋ก ํ๋ณ length = len(queue) for i in range(length // 2): if queue[i] != queue[length - 1 - i]: return False return True
ย
![[Leetcode] 234. Palindrome Linked List](https://reo91004.notion.site/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fb4dac9d0-810c-47c4-800c-0ca10b8d0529%2Fde29f40a-05a3-4aec-b112-7e56072966a0%2FLeetCode_Logo_Black.png?table=block&id=e2dfd2a1-b73a-49e3-a501-9978bfd18c88&cache=v2)
![[Leetcode] 234. Palindrome Linked List](https://reo91004.notion.site/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fb4dac9d0-810c-47c4-800c-0ca10b8d0529%2F45a3427e-47fb-412a-a090-3bf6d1afdb04%2Fleetcode.png?table=block&id=e2dfd2a1-b73a-49e3-a501-9978bfd18c88&cache=v2)

๋๊ธ