leetcode 206 python

Solutions on MaxInterview for leetcode 206 python by the best coders in the world

showing results for - "leetcode 206 python"
Linus
18 Oct 2018
1class Solution:
2    def reverseList(self, head: ListNode) -> ListNode:
3        if not head or not head.next:
4            return head
5        pre,tmp=None,None
6        while(head):
7            tmp=head.next
8            head.next=pre
9            pre=head
10            head=tmp
11        return pre