Created
February 7, 2017 07:37
-
-
Save Chen-tao/b521f36ab024a0e9de3a1186ea88cd91 to your computer and use it in GitHub Desktop.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) { | |
//set node val next , and delete next node | |
node.val = node.next.val; | |
node.next = node.next.next; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment