Last active
October 5, 2022 20:22
-
-
Save FrqSalah/706ecf46ee80776702c6f211ed35e744 to your computer and use it in GitHub Desktop.
206. Reverse Linked List, Leet Code solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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