Skip to content

Commit bfa59d3

Browse files
refactor 237
1 parent 786d090 commit bfa59d3

File tree

1 file changed

+5
-11
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+5
-11
lines changed

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@
22

33
import com.fishercoder.common.classes.ListNode;
44

5-
/**237. Delete Node in a Linked List
6-
*
7-
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.
8-
9-
Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, the linked list should become 1 -> 2 -> 4 after calling your function.
5+
/**
6+
* 237. Delete Node in a Linked List
7+
* Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.
8+
* Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3,
9+
* the linked list should become 1 -> 2 -> 4 after calling your function.
1010
*/
1111
public class _237 {
1212

13-
/**We're not really deleting the node, but we're overwriting this node's value with its successor's value,
14-
* and then append its successor's successor to its new successor.
15-
*
16-
* In graph, it's like this:
17-
* Given this list: 1->2->3->4->null and only access to this to-be-deleted node 3
18-
* we overwrite 3 with 4, and then assign null to be 4's next.*/
1913
public void deleteNode(ListNode node) {
2014
node.val = node.next.val;
2115
node.next = node.next.next;

0 commit comments

Comments
 (0)