Skip to content

Commit

Permalink
feat: 递归实现反转单链表的js实现 (azl397985856#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnynudt authored and azl397985856 committed Sep 20, 2019
1 parent d7d0445 commit 24982ab
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions problems/206.reverse-linked-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,24 @@ public:
}
};
```

### JavaScript实现
```javascript
var reverseList = function(head) {
// 递归结束条件
if (head === null || head.next === null) {
return head
}

// 递归反转 子链表
let newReverseList = reverseList(head.next)
// 获取原来链表的第2个节点newReverseListTail
let newReverseListTail = head.next
// 调整原来头结点和第2个节点的指向
newReverseListTail.next = head
head.next = null

// 将调整后的链表返回
return newReverseList
}
```

0 comments on commit 24982ab

Please sign in to comment.