Skip to content

Instantly share code, notes, and snippets.

@nanjingdaqi
Created November 4, 2018 07:24
Show Gist options
  • Save nanjingdaqi/acc678e67da128005493a20f3270794d to your computer and use it in GitHub Desktop.
Save nanjingdaqi/acc678e67da128005493a20f3270794d to your computer and use it in GitHub Desktop.
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