File tree Expand file tree Collapse file tree 3 files changed +51
-2
lines changed
src/com/andavid/leetcode/_237 Expand file tree Collapse file tree 3 files changed +51
-2
lines changed Original file line number Diff line number Diff line change 9
9
## Easy
10
10
11
11
以下是 LeetCode 官方精选的经典面试问题列表:
12
- [ Top Interview Questions Easy Collection] [ easy ]
12
+ [ Top Interview Questions Easy Collection] [ interview- easy]
13
13
14
14
** Array**
15
15
41
41
| 38 | [ count-and-say] [ 038 ] |
42
42
| 14 | [ Longest Common Prefix] [ 014 ] |
43
43
44
+ ** Linked List**
45
+
46
+ | # | Title |
47
+ | :--: | :------------------------------------------ |
48
+ | 237 | [ Delete Node in a Linked List] [ 237 ] |
49
+
50
+
44
51
45
52
** 其他**
46
53
52
59
53
60
[ leetcode ] : https://leetcode.com/problemset/all/
54
61
[ blankj ] : https://github.com/Blankj/awesome-java-leetcode
55
- [ easy ] : https://leetcode.com/explore/interview/card/top-interview-questions-easy/
62
+ [ interview- easy] : https://leetcode.com/explore/interview/card/top-interview-questions-easy/
56
63
57
64
[ 026 ] : https://github.com/andavid/leetcode-java/blob/master/note/026/README.md
58
65
[ 121 ] : https://github.com/andavid/leetcode-java/blob/master/note/121/README.md
75
82
[ 028 ] : https://github.com/andavid/leetcode-java/blob/master/note/028/README.md
76
83
[ 038 ] : https://github.com/andavid/leetcode-java/blob/master/note/038/README.md
77
84
[ 014 ] : https://github.com/andavid/leetcode-java/blob/master/note/014/README.md
85
+ [ 237 ] : https://github.com/andavid/leetcode-java/blob/master/note/237/README.md
Original file line number Diff line number Diff line change
1
+ # [ Delete Node in a Linked List] [ title ]
2
+
3
+ ## Description
4
+
5
+ Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.
6
+
7
+ 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.
8
+
9
+ ## 思路
10
+
11
+ 常规方法是修改该节点前面的那个节点。由于只能访问当前节点,且当前节点不是最末尾的节点,可以放心的把其 next 节点的值拷贝过来,并修改其 next 节点。
12
+
13
+ ## [ 完整代码] [ src ]
14
+
15
+ ``` java
16
+ class Solution {
17
+ public void deleteNode (ListNode node ) {
18
+ node. val = node. next. val;
19
+ node. next = node. next. next;
20
+ }
21
+ }
22
+ ```
23
+
24
+ [ title ] : https://leetcode.com/problems/delete-node-in-a-linked-list
25
+ [ src ] : https://github.com/andavid/leetcode-java/blob/master/src/com/andavid/leetcode/_237/Solution.java
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+
3
+ public void deleteNode (ListNode node ) {
4
+ node .val = node .next .val ;
5
+ node .next = node .next .next ;
6
+ }
7
+
8
+ public class ListNode {
9
+ int val ;
10
+ ListNode next ;
11
+ ListNode (int x ) {
12
+ val = x ;
13
+ }
14
+ }
15
+
16
+ }
You can’t perform that action at this time.
0 commit comments