Skip to content

Instantly share code, notes, and snippets.

@Chen-tao
Created February 7, 2017 07:37
Show Gist options
  • Save Chen-tao/b521f36ab024a0e9de3a1186ea88cd91 to your computer and use it in GitHub Desktop.
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.
/**
* 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