package main
type ListNode struct{
Val int
Next *ListNode
}package main
funcreverseList(head *ListNode)*ListNode {if head ==nil{return head
}
a := head
b := head.Next
for;b !=nil;{
c := b.Next
b.Next = a
a = b
b = c
}
head.Next =nilreturn a
}
Python
classListNode:def__init__(self, x):
self.val = x
self.next=NoneclassSolution:defreverseList(self, head: ListNode)-> ListNode:ifnot head:return head
a = head
b = head.nextwhile b:
c = b.next
b.next= a
a = b
b = c
head.next=Nonereturn a
C#
publicclassListNode{publicint val;publicListNode next;publicListNode(int x){ val = x;}}publicclassSolution{publicListNodeReverseList(ListNode head){if(head ==null)returnnull;var a = head;var b = head.next;while(b !=null){var c = b.next;
b.next = a;
a = b;
b = c;}
head.next =null;return a;}}