🚀 Leetcode using AI :robot:
A GPT - 2 Model for Leetcode Questions implemented in Python
This project uses a GPT - 2 model to generate solutions for Leetcode questions. However, due to the bias in GPT - 2, the answers might not always be reasonable.
🚀 Quick Start
Prerequisites
You need to have the transformers
library installed. You can install it using pip install transformers
.
Example usage
from transformers import AutoTokenizer, AutoModelWithLMHead
tokenizer = AutoTokenizer.from_pretrained("gagan3012/project-code-py")
model = AutoModelWithLMHead.from_pretrained("gagan3012/project-code-py")
✨ Features
- Multiple Models: Two models have been developed for different use cases, which can be found at https://huggingface.co/gagan3012.
- Web Demo: A Streamlit webapp has been set up for easy use of the model. You can access it at Streamlit App.
📚 Documentation
Model Details
The model weights can be found at the following links:
Example Results
Question
Write a function to delete a node in a singly - linked list. You will not be given access to the head of the list, instead you will be given access to the node to be deleted directly. It is guaranteed that the node to be deleted is not a tail node in the list.
Answer
""" Write a function to delete a node in a singly-linked list. You will not be given access to the head of the list, instead you will be given access to the node to be deleted directly. It is guaranteed that the node to be deleted is not a tail node in the list.
For example,
a = 1->2->3
b = 3->1->2
t = ListNode(-1, 1)
Note: The lexicographic ordering of the nodes in a tree matters. Do not assign values to nodes in a tree.
Example 1:
Input: [1,2,3]
Output: 1->2->5
Explanation: 1->2->3->3->4, then 1->2->5[2] and then 5->1->3->4.
Note:
The length of a linked list will be in the range [1, 1000].
Node.val must be a valid LinkedListNode type.
Both the length and the value of the nodes in a linked list will be in the range [-1000, 1000].
All nodes are distinct.
"""
class Solution:
def deleteNode(self, head: ListNode, val: int) -> None:
"""
BFS
Linked List
:param head: ListNode
:param val: int
:return: ListNode
"""
if head is not None:
return head
dummy = ListNode(-1, 1)
dummy.next = head
dummy.next.val = val
dummy.next.next = head
dummy.val = ""
s1 = Solution()
print(s1.deleteNode(head))
print(s1.deleteNode(-1))
print(s1.deleteNode(-1))
🤝 Contributions
If you would like to improve the model, contributions are welcome. Check out CONTRIBUTIONS.md
⭐ Favour
It would be highly motivating if you can STAR⭐ this repo if you find it helpful.
⚠️ Important Note
Due to the bias in GPT - 2, the answers might not make sense in some cases.
💡 Usage Tip
You can try different models (GPT - 2
or DistilGPT - 2
) according to your specific needs.