1
# Runtime: 71 ms (Top 18.71%) | Memory: 15.5 MB (Top 28.33%)
2
# Definition for singly-linked list.
3
# class ListNode:
4
# def __init__(self, val=0, next=None):
5
# self.val = val
6
# self.next = next
7
class Solution:
8
def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
9
if head == None or head.next == None:
10
return head
11
p = None
12
while head != None:
13
temp = head.next
14
head.next = p
15
p = head
16
head = temp
17
return p

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0