1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-16 16:36:56 +02:00
LeetCode/java/reverse-linked-list.java
Matej Focko 7dc90ebe06
java: add «206. Reverse Linked List»
Signed-off-by: Matej Focko <mfocko@redhat.com>
2024-03-21 10:42:25 +01:00

14 lines
236 B
Java

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;
}
}