Created
July 31, 2018 09:37
-
-
Save luojiyin1987/531ca05072aa0a08b945d72099f8cc3d to your computer and use it in GitHub Desktop.
Reverse Linked List
This file contains hidden or 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
| # Definition for singly-linked list. | |
| # class ListNode: | |
| # def __init__(self, x): | |
| # self.val = x | |
| # self.next = None | |
| class Solution: | |
| def reverseList(self, head): | |
| """ | |
| :type head: ListNode | |
| :rtype: ListNode | |
| """ | |
| dummy = ListNode(0) | |
| while head: | |
| next = head.next | |
| head.next = dummy.next | |
| dummy.next = head | |
| head = next | |
| return dummy.next |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment