Created
November 4, 2018 07:24
-
-
Save nanjingdaqi/acc678e67da128005493a20f3270794d to your computer and use it in GitHub Desktop.
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 Node { | |
int val; | |
Node next; | |
} | |
public Node reverseList(Node head) { | |
if (head == null || head.next == null) { | |
return head; | |
} | |
Node newHead = new Node(); | |
while(head.next != null) { | |
Node cur = head.next; | |
head.next = cur.next; | |
cur.next = newHead.next; | |
newHead.next = cur; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment