# 反转链表
- 反转链表
来源:力扣(LeetCode) 链接 (opens new window):https://leetcode.cn/problems/reverse-linked-list/ 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
# 问题
给你单链表的头节点 head ,请你反转链表,并返回反转后的链表
# 思路
var reverseList = function (head) {
let pre = null;
let cur = head;
while (cur !== null) {
let tmp = cur.next;
cur.next = pre;
pre = cur;
cur = tmp;
}
return pre;
};