FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode/java/237_Delete_Node_in_a_Linked_List.java at master · jakehoare/leetcode · GitHub
jakehoare
/
leetcode
Public
Notifications
You must be signed in to change notification settings
Fork
30
Star
51
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
leetcode
/
java
/
237_Delete_Node_in_a_Linked_List.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
26 lines (23 loc) · 763 Bytes
Breadcrumbs
leetcode
/
java
/
237_Delete_Node_in_a_Linked_List.java
Copy path
File metadata and controls
26 lines (23 loc) · 763 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
https://leetcode.com/problems/delete-node-in-a-linked-list/
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.
Copy value of next node then link to node after next and remove next node.
Time - O(1)
Space - O(1)
*/
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
public
class
Solution
{
public
void
deleteNode
(
ListNode
node
) {
node
.
val
=
node
.
next
.
val
;
// copy value of next node
ListNode
temp
=
node
.
next
;
// save next node
node
.
next
=
node
.
next
.
next
;
// link node to node after next
temp
=
null
;
// delete next node
}
}
Back
|
FazBrowse Home
|
New Git URL