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 intersection of two linked lists #16

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/intersection-of-two-linked-lists.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ defaultValue="java"
values={[
{ label: 'Java', value: 'java', },
{ label: 'C++', value: 'cpp', },
{ label: 'Python', value: 'python', },
]
}>
<TabItem value="java">
Expand Down Expand Up @@ -80,6 +81,22 @@ public:
};
```

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

```python
# Intersection of Two Linked Lists
soulmachine marked this conversation as resolved.
Show resolved Hide resolved
# Time Complexity: O(m+n), Space Complexity: O(1)
class Solution:
def getIntersectionNode(self, headA, headB):
a, b = headA, headB
while a != b:
a = headB if a == None else a.next
b = headA if b == None else b.next

return a # return b is also OK
```

</TabItem>
</Tabs>

Expand Down