数组&链表
1.反转链表
Question:反转一个单链表。
Input: 1->2->3->4->5->NULL
Output: 5->4->3->2->1->NULL
Code:
# 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):
#定义两个指针,pre指向head,last为None
pre,last = head,None
#判断头节点是否为空
while pre: