store list in a array(python list) compare node start from middle, if val not equal, return false
Best Solution
1 2 3 4 5 6 7 8 9 10
def(self, head): """ :type head: ListNode :rtype: bool """ s = [] while head isnotNone: s.append(head.val) head = head.next return s == list(reversed(s))
Time complexity: O(n) Space complexity: O(3)
use python defined function to check if reversed list equal to original list
近期评论