206-反转链表 代码:
var reverseList = function(head) {
let prev = null;
let curr = head;
while(curr !== null){
const next = curr.next;
curr.next = prev;
prev = curr;
curr = next;
}
return prev;
};
```javascript
var reverseList1 = function(head){
if(head ==null || head.next == null){
return head
}
const p = reverseList1(head.next);
head.next.next = head;
head.next = null;
return p;
}
这个视频思路很清楚:https://leetcode-cn.com/problems/reverse-linked-list/solution/shi-pin-jiang-jie-die-dai-he-di-gui-hen-hswxy/
笔记我记在notablity里了 P15左右
|