# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def reverseList(self, head):
if(head==None):return None
if(head.next==None):return head
# pre=head
# p=head.next
# pre.next=None
# nxt=None
new_head=None
while head:
p=head
head=head.next
p.next=new_head
new_head=p
return new_head
相关文章
- LeetCode之237. Delete Node in a Linked List
- 142. Linked List Cycle II - Leetcode
- Leetcode 203 Remove Linked List Elements 链表
- [LeetCode]题解(python):007-Reverse Integer
- Leetcode 344:Reverse String 反转字符串(python、java)
- Python: How to iterate list in reverse order
- [LeetCode]题解(python):086 - Partition List
- [LeetCode]题解(python):019-Remove Nth Node From End of List
- Java [Leetcode 234]Palindrome Linked List
- leetcode:142. Linked List Cycle II(Java)解答