Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added python code middle of the linked list #15

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/linked-list/middle-of-the-linked-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ defaultValue="cpp"
values={[
{ label: 'Java', value: 'java', },
{ label: 'C++', value: 'cpp', },
{ label: 'Python', value: 'python', },
]
}>
<TabItem value="java">
Expand Down Expand Up @@ -50,6 +51,22 @@ public:
};
```

</TabItem>
<TabItem value="python">

```python
# Middle of the Linked List
# 时间复杂度O(n),空间复杂度O(1)
class Solution:
def middleNode(self, head):
# 设置两个指针,一个快一个慢
soulmachine marked this conversation as resolved.
Show resolved Hide resolved
slow, fast = head, head
while fast and fast.next:
slow = slow.next
fast = fast.next.next
return slow
```

</TabItem>
</Tabs>

Expand Down