Skip to content

Instantly share code, notes, and snippets.

@JoyceeLee
Created June 26, 2014 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoyceeLee/16128f844bfb476eb21c to your computer and use it in GitHub Desktop.
Save JoyceeLee/16128f844bfb476eb21c to your computer and use it in GitHub Desktop.
/*2.3 Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node.
* EXAMPLE
* Input: the node c from the linked list a->b->c->d->e
* Result: nothing is returned, but the new linked list looks like a->b->d->e
* 只给出该list中要剪去的node,从链中剪去该node
*/
public class Solution {
public void deleteNode(ListNode n) {
if(n==null || n.next==null) // not in the middle
return;
n.val = n.next.val
n.next = n.next.next;
return;
}
}
@jason51122
Copy link

  1. Good job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment