🚀 基于人工智能的LeetCode解题方案 :robot:
本项目使用GPT - 2模型,以Python语言为LeetCode问题提供解答。
注意:由于GPT - 2存在偏差,某些情况下给出的答案可能不合理。
贡献:如果您想让这个模型变得更好,欢迎贡献代码。请查看贡献指南。
📢 请求帮助:
如果您觉得这个仓库有帮助,给它点个星⭐将极大地激励开发者。
✨ 主要特性
为不同的使用场景开发了两个模型,可在https://huggingface.co/gagan3012 找到。
模型权重可在以下链接获取:GPT - 2 和 DistilGPT - 2
📦 安装指南
依赖安装
from transformers import AutoTokenizer, AutoModelWithLMHead
tokenizer = AutoTokenizer.from_pretrained("gagan3012/project-code-py")
model = AutoModelWithLMHead.from_pretrained("gagan3012/project-code-py")
💻 使用示例
基础用法
from transformers import AutoTokenizer, AutoModelWithLMHead
tokenizer = AutoTokenizer.from_pretrained("gagan3012/project-code-py")
model = AutoModelWithLMHead.from_pretrained("gagan3012/project-code-py")
📚 详细文档
演示地址

已搭建一个Streamlit网页应用来使用该模型:https://share.streamlit.io/gagan3012/project-code-py/app.py

示例结果
问题
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.
答案
""" 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))