Skip to content

Commit 7978d30

Browse files
refactor 237
1 parent 2dad12b commit 7978d30

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

src/main/java/com/fishercoder/solutions/_237.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,24 @@
66
* 237. Delete Node in a Linked List
77
*
88
* Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.
9-
* Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3,
10-
* the linked list should become 1 -> 2 -> 4 after calling your function.
9+
*
10+
* Given linked list -- head = [4,5,1,9], which looks like following:
11+
*
12+
* Example 1:
13+
* Input: head = [4,5,1,9], node = 5
14+
* Output: [4,1,9]
15+
* Explanation: You are given the second node with value 5, the linked list should become 4 -> 1 -> 9 after calling your function.
16+
*
17+
* Example 2:
18+
* Input: head = [4,5,1,9], node = 1
19+
* Output: [4,5,9]
20+
* Explanation: You are given the third node with value 1, the linked list should become 4 -> 5 -> 9 after calling your function.
21+
*
22+
* Note:
23+
* The linked list will have at least two elements.
24+
* All of the nodes' values will be unique.
25+
* The given node will not be the tail and it will always be a valid node of the linked list.
26+
* Do not return anything from your function.
1127
*/
1228
public class _237 {
1329

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.common.classes.ListNode;
4+
import com.fishercoder.common.utils.CommonUtils;
5+
import com.fishercoder.solutions._237;
6+
import org.junit.BeforeClass;
7+
import org.junit.Test;
8+
9+
import java.util.Arrays;
10+
11+
public class _237Test {
12+
private static _237.Solution1 solution1;
13+
private static ListNode head;
14+
15+
@BeforeClass
16+
public static void setup() {
17+
solution1 = new _237.Solution1();
18+
}
19+
20+
@Test
21+
public void test1() {
22+
head = ListNode.createSinglyLinkedList(Arrays.asList(4, 5, 1, 9));
23+
CommonUtils.printList(head);
24+
solution1.deleteNode(head.next);
25+
CommonUtils.printList(head);
26+
}
27+
28+
}

0 commit comments

Comments
 (0)