palindrome1 [LeetCode] Palindrome Linked List 파이썬 class Solution: # @param {ListNode} head # @return {boolean} def isPalindrome(self, head): # get mid point cur = head N = 0 while cur: N += 1 cur = cur.next mid = N//2 i = 0 def reverse(head): ans = None while head: nx = head.next head.next = ans ans = head head = nx return ans first = second = head # to mid point while i < mid: second = second.next i += 1 second = reverse(second) # check palind.. 2021. 4. 6. 이전 1 다음