Class Solution
java.lang.Object
g0201_0300.s0237_delete_node_in_a_linked_list.Solution
237 - Delete Node in a Linked List.<p>Easy</p>
<p>Write a function to <strong>delete a node</strong> in a singly-linked list. You will <strong>not</strong> be given access to the <code>head</code> of the list, instead you will be given access to <strong>the node to be deleted</strong> directly.</p>
<p>It is <strong>guaranteed</strong> that the node to be deleted is <strong>not a tail node</strong> in the list.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2020/09/01/node1.jpg" alt="" /></p>
<p><strong>Input:</strong> head = [4,5,1,9], node = 5</p>
<p><strong>Output:</strong> [4,1,9]</p>
<p><strong>Explanation:</strong> You are given the second node with value 5, the linked list should become 4 -> 1 -> 9 after calling your function.</p>
<p><strong>Example 2:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2020/09/01/node2.jpg" alt="" /></p>
<p><strong>Input:</strong> head = [4,5,1,9], node = 1</p>
<p><strong>Output:</strong> [4,5,9]</p>
<p><strong>Explanation:</strong> You are given the third node with value 1, the linked list should become 4 -> 5 -> 9 after calling your function.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> head = [1,2,3,4], node = 3</p>
<p><strong>Output:</strong> [1,2,4]</p>
<p><strong>Example 4:</strong></p>
<p><strong>Input:</strong> head = [0,1], node = 0</p>
<p><strong>Output:</strong> [1]</p>
<p><strong>Example 5:</strong></p>
<p><strong>Input:</strong> head = [-3,5,-99], node = -3</p>
<p><strong>Output:</strong> [5,-99]</p>
<p><strong>Constraints:</strong></p>
<ul>
<li>The number of the nodes in the given list is in the range <code>[2, 1000]</code>.</li>
<li><code>-1000 <= Node.val <= 1000</code></li>
<li>The value of each node in the list is <strong>unique</strong>.</li>
<li>The <code>node</code> to be deleted is <strong>in the list</strong> and is <strong>not a tail</strong> node</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
deleteNode
-