File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ low = temp 即可。然后重复执行上诉操作直至最后,这样则完成
33
33
34
34
我会对每个关键点进行注释,大家可以参考动图理解。
35
35
36
+ Java Code:
36
37
``` java
37
38
class Solution {
38
39
public ListNode reverseList (ListNode head ) {
@@ -62,9 +63,27 @@ class Solution {
62
63
63
64
}
64
65
```
66
+ JS Code:
67
+ ``` javascript
68
+ var reverseList = function (head ) {
69
+ if (! head || ! head .next ) {
70
+ return head;
71
+ }
72
+ let low = null ;
73
+ let pro = head;
74
+ while (pro) {
75
+ let temp = pro;
76
+ pro = pro .next ;
77
+ temp .next = low;
78
+ low = temp;
79
+ }
80
+ return low;
81
+ };
82
+ ```
65
83
66
84
上面的迭代写法是不是搞懂啦,现在还有一种递归写法,不是特别容易理解,刚开始刷题的同学,可以只看迭代解法。
67
85
86
+ Java Code:
68
87
``` java
69
88
class Solution {
70
89
public ListNode reverseList (ListNode head ) {
@@ -86,3 +105,16 @@ class Solution {
86
105
87
106
```
88
107
108
+ JS Code:
109
+ ``` javascript
110
+ var reverseList = function (head ) {
111
+ if (! head || ! head .next ) {
112
+ return head;
113
+ }
114
+ let pro = reverseList (head .next );
115
+ head .next .next = head;
116
+ head .next = null ;
117
+ return pro;
118
+ };
119
+ ```
120
+
You can’t perform that action at this time.
0 commit comments