1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-19 01:36:57 +02:00
LeetCode/java/reverse-linked-list.java

15 lines
236 B
Java
Raw Permalink Normal View History

class Solution {
public ListNode reverseList(ListNode head) {
ListNode tail = null;
while (head != null) {
var tmp = head.next;
head.next = tail;
tail = head;
head = tmp;
}
return tail;
}
}