MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / reverseList

Method reverseList

IterativeReverseLinkedList.java:2–14  ·  view source on GitHub ↗
(ListNode head)

Source from the content-addressed store, hash-verified

1class Solution {
2 public ListNode reverseList(ListNode head) {
3 ListNode cur=head;
4 ListNode prev = null;
5 while(cur!=null)
6 {
7 ListNode newNext = cur.next;
8 cur.next = prev;
9 prev=cur;
10 cur=newNext;
11 }
12 head = prev;
13 return head;
14 }
15}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected