leetcode 206 补充js版解法

pull/20/head
daluozha 2021-04-27 18:12:18 +08:00
parent e8255d73ec
commit 39683f1794
1 changed files with 32 additions and 0 deletions

View File

@ -33,6 +33,7 @@ low = temp 即可。然后重复执行上诉操作直至最后,这样则完成
Java Code:
```java
class Solution {
public ListNode reverseList(ListNode head) {
@ -62,9 +63,27 @@ class Solution {
}
```
JS Code:
```javascript
var reverseList = function(head) {
if(!head || !head.next) {
return head;
}
let low = null;
let pro = head;
while (pro) {
let temp = pro;
pro = pro.next;
temp.next = low;
low = temp;
}
return low;
};
```
Java Code:
```java
class Solution {
public ListNode reverseList(ListNode head) {
@ -86,3 +105,16 @@ class Solution {
```
JS Code:
```javascript
var reverseList = function(head) {
if (!head || !head.next) {
return head;
}
let pro = reverseList(head.next);
head.next.next = head;
head.next = null;
return pro;
};
```