Skip to content

Commit 67b94ca

Browse files
committed
DeleteNodeInALinkedList237
1 parent cda26a2 commit 67b94ca

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

Diff for: README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@
4141

4242

4343

44-
# Total: 206
44+
# Total: 207
4545

4646
| Easy | Medium | Hard | - |
4747
|:----:|:-------:|:----:|:-:|
48-
| 47 | 120 | 38 | 1 |
48+
| 48 | 120 | 38 | 1 |
4949

5050

5151
| Question | Solution | Difficulty |
@@ -183,6 +183,7 @@
183183
| [230. Kth Smallest Element in a BST](https://leetcode.com/problems/kth-smallest-element-in-a-bst/) | [Solution](https://github.com/fluency03/leetcode-java/blob/master/src/KthSmallestElementInABST230.java) | Medium |
184184
| [233. Number of Digit One](https://leetcode.com/problems/number-of-digit-one/) | [Solution](https://github.com/fluency03/leetcode-java/blob/master/src/NumberOfDigitOne233.java) | Hard |
185185
| [234. Palindrome Linked List](https://leetcode.com/problems/palindrome-linked-list/) | [Solution](https://github.com/fluency03/leetcode-java/blob/master/src/PalindromeLinkedList234.java) | Easy |
186+
| [237. Delete Node in a Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list/) | [Solution](https://github.com/fluency03/leetcode-java/blob/master/src/DeleteNodeInALinkedList237.java) | Easy |
186187
| [240. Search a 2D Matrix II](https://leetcode.com/problems/search-a-2d-matrix-ii/) | [Solution](https://github.com/fluency03/leetcode-java/blob/master/src/SearchA2DMatrixII240.java) | Medium |
187188
| [241. Different Ways to Add Parentheses](https://leetcode.com/problems/different-ways-to-add-parentheses/) | [Solution](https://github.com/fluency03/leetcode-java/blob/master/src/DifferentWaysToAddParentheses241.java) | Medium |
188189
| [242. Valid Anagram](https://leetcode.com/problems/valid-anagram/) | [Solution](https://github.com/fluency03/leetcode-java/blob/master/src/ValidAnagram242.java) | Easy |

Diff for: src/DeleteNodeInALinkedList237.java

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Write a function to delete a node (except the tail) in a singly linked list,
3+
* given only access to that node.
4+
*
5+
* Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third
6+
* node with value 3, the linked list should become 1 -> 2 -> 4 after calling
7+
* your function.
8+
*/
9+
10+
/**
11+
* Definition for singly-linked list.
12+
* public class ListNode {
13+
* int val;
14+
* ListNode next;
15+
* ListNode(int x) { val = x; }
16+
* }
17+
*/
18+
19+
public class DeleteNodeInALinkedList237 {
20+
public void deleteNode(ListNode node) {
21+
if (node != null && node.next != null) {
22+
node.val = node.next.val;
23+
node.next = node.next.next;
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)