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