|
| 1 | +<h2>237. Delete Node in a Linked List</h2><h3>Easy</h3><hr><div><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> |
| 2 | + |
| 3 | +<p>It is <strong>guaranteed</strong> that the node to be deleted is <strong>not a tail node</strong> in the list.</p> |
| 4 | + |
| 5 | +<p> </p> |
| 6 | +<p><strong>Example 1:</strong></p> |
| 7 | +<img alt="" src="https://assets.leetcode.com/uploads/2020/09/01/node1.jpg" style="width: 450px; height: 322px;"> |
| 8 | +<pre><strong>Input:</strong> head = [4,5,1,9], node = 5 |
| 9 | +<strong>Output:</strong> [4,1,9] |
| 10 | +<strong>Explanation: </strong>You are given the second node with value 5, the linked list should become 4 -> 1 -> 9 after calling your function. |
| 11 | +</pre> |
| 12 | + |
| 13 | +<p><strong>Example 2:</strong></p> |
| 14 | +<img alt="" src="https://assets.leetcode.com/uploads/2020/09/01/node2.jpg" style="width: 450px; height: 354px;"> |
| 15 | +<pre><strong>Input:</strong> head = [4,5,1,9], node = 1 |
| 16 | +<strong>Output:</strong> [4,5,9] |
| 17 | +<strong>Explanation: </strong>You are given the third node with value 1, the linked list should become 4 -> 5 -> 9 after calling your function. |
| 18 | +</pre> |
| 19 | + |
| 20 | +<p><strong>Example 3:</strong></p> |
| 21 | + |
| 22 | +<pre><strong>Input:</strong> head = [1,2,3,4], node = 3 |
| 23 | +<strong>Output:</strong> [1,2,4] |
| 24 | +</pre> |
| 25 | + |
| 26 | +<p><strong>Example 4:</strong></p> |
| 27 | + |
| 28 | +<pre><strong>Input:</strong> head = [0,1], node = 0 |
| 29 | +<strong>Output:</strong> [1] |
| 30 | +</pre> |
| 31 | + |
| 32 | +<p><strong>Example 5:</strong></p> |
| 33 | + |
| 34 | +<pre><strong>Input:</strong> head = [-3,5,-99], node = -3 |
| 35 | +<strong>Output:</strong> [5,-99] |
| 36 | +</pre> |
| 37 | + |
| 38 | +<p> </p> |
| 39 | +<p><strong>Constraints:</strong></p> |
| 40 | + |
| 41 | +<ul> |
| 42 | + <li>The number of the nodes in the given list is in the range <code>[2, 1000]</code>.</li> |
| 43 | + <li><code>-1000 <= Node.val <= 1000</code></li> |
| 44 | + <li>The value of each node in the list is <strong>unique</strong>.</li> |
| 45 | + <li>The <code>node</code> to be deleted is <strong>in the list</strong> and is <strong>not a tail</strong> node</li> |
| 46 | +</ul> |
| 47 | +</div> |
0 commit comments