Skip to content

Instantly share code, notes, and snippets.

@FrqSalah
Last active October 5, 2022 20:22
Show Gist options
  • Save FrqSalah/706ecf46ee80776702c6f211ed35e744 to your computer and use it in GitHub Desktop.
Save FrqSalah/706ecf46ee80776702c6f211ed35e744 to your computer and use it in GitHub Desktop.
206. Reverse Linked List, Leet Code solution
public class Solution {
public ListNode ReverseList(ListNode head) {
ListNode curr = head;
ListNode prev = null;
ListNode temp = null;
while(curr != null)
{
temp = curr.next; // next value
curr.next = prev; // Previous value
prev = curr;
curr= temp;
}
return prev;
}
}
/**
* Definition for singly-linked list.
* public class ListNode {
* public int val;
* public ListNode next;
* public ListNode(int val=0, ListNode next=null) {
* this.val = val;
* this.next = next;
* }
* }
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment