date:
updated:
nowcoder练习
NC78 反转列表
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
class Solution: def ReverseList(self, pHead): if not pHead: return None newpHead = None while pHead: pHead.next, newpHead, pHead = newpHead, pHead, pHead.next return newpHead
|
令后一个结点指向前一个结点,并且将表头指针指向最后一个结点即可。