mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-09 15:59:06 +01:00
java: add «206. Reverse Linked List»
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
84ba9d343b
commit
7dc90ebe06
1 changed files with 14 additions and 0 deletions
14
java/reverse-linked-list.java
Normal file
14
java/reverse-linked-list.java
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue