mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-09 15:59:06 +01:00
25 lines
546 B
C#
25 lines
546 B
C#
/**
|
|
* Definition for singly-linked list.
|
|
* public class ListNode {
|
|
* public int val;
|
|
* public ListNode next;
|
|
* public ListNode(int val=0, ListNode next=null) {
|
|
* this.val = val;
|
|
* this.next = next;
|
|
* }
|
|
* }
|
|
*/
|
|
public class Solution {
|
|
public ListNode ReverseList(ListNode head) {
|
|
ListNode next = null;
|
|
|
|
while (head != null) {
|
|
var toRight = head.next;
|
|
head.next = next;
|
|
next = head;
|
|
head = toRight;
|
|
}
|
|
|
|
return next;
|
|
}
|
|
}
|