添加py和js

pull/33/head
jaredliw 2021-07-12 17:24:38 +08:00
parent 3acd44f653
commit dff62af40a
1 changed files with 32 additions and 0 deletions

View File

@ -71,6 +71,7 @@ class Solution {
C++ Code:
```cpp
class Solution {
public:
ListNode* middleNode(ListNode* head) {
ListNode * fast = head;//快指针
@ -86,3 +87,34 @@ public:
};
```
JS Code:
```js
var middleNode = function(head) {
let fast = head;//快指针
let slow = head;//慢指针
//循环条件,思考一下跳出循环的情况
while (fast && fast.next) {
fast = fast.next.next;
slow = slow.next;
}
//返回slow指针指向的节点
return slow
};
```
Python Code:
```py
class Solution:
def middleNode(self, head: ListNode) -> ListNode:
fast = head #
slow = head #
#
while fast is not None and fast.next is not None:
fast = fast.next.next
slow = slow.next
# slow
return slow
```