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 @@ -71,6 +71,7 @@ class Solution {
71
71
C++ Code:
72
72
73
73
``` cpp
74
+ class Solution {
74
75
public:
75
76
ListNode* middleNode(ListNode* head) {
76
77
ListNode * fast = head;//快指针
@@ -86,3 +87,34 @@ public:
86
87
};
87
88
```
88
89
90
+ JS Code:
91
+
92
+ ```js
93
+ var middleNode = function(head) {
94
+ let fast = head;//快指针
95
+ let slow = head;//慢指针
96
+ //循环条件,思考一下跳出循环的情况
97
+ while (fast && fast.next) {
98
+ fast = fast.next.next;
99
+ slow = slow.next;
100
+ }
101
+ //返回slow指针指向的节点
102
+ return slow
103
+ };
104
+ ```
105
+
106
+ Python Code:
107
+
108
+ ``` py
109
+ class Solution :
110
+ def middleNode (self , head : ListNode) -> ListNode:
111
+ fast = head # 快指针
112
+ slow = head # 慢指针
113
+ # 循环条件,思考一下跳出循环的情况
114
+ while fast is not None and fast.next is not None :
115
+ fast = fast.next.next
116
+ slow = slow.next
117
+ # 返回slow指针指向的节点
118
+ return slow
119
+ ```
120
+
You can’t perform that action at this time.
0 commit comments