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->3b = 3->1->2t = 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->5Explanation: 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."""# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = NoneclassSolution:
defdeleteNode(self, head: ListNode, val: int) -> None:
""" BFS Linked List :param head: ListNode :param val: int :return: ListNode """if head isnotNone:
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))
Runs of gagan3012 project-code-py-small on huggingface.co
23
Total runs
0
24-hour runs
2
3-day runs
0
7-day runs
4
30-day runs
More Information About project-code-py-small huggingface.co Model
project-code-py-small huggingface.co
project-code-py-small huggingface.co is an AI model on huggingface.co that provides project-code-py-small's model effect (), which can be used instantly with this gagan3012 project-code-py-small model. huggingface.co supports a free trial of the project-code-py-small model, and also provides paid use of the project-code-py-small. Support call project-code-py-small model through api, including Node.js, Python, http.
project-code-py-small huggingface.co is an online trial and call api platform, which integrates project-code-py-small's modeling effects, including api services, and provides a free online trial of project-code-py-small, you can try project-code-py-small online for free by clicking the link below.
gagan3012 project-code-py-small online free url in huggingface.co:
project-code-py-small is an open source model from GitHub that offers a free installation service, and any user can find project-code-py-small on GitHub to install. At the same time, huggingface.co provides the effect of project-code-py-small install, users can directly use project-code-py-small installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
project-code-py-small install url in huggingface.co: