Created
June 26, 2014 22:27
-
-
Save JoyceeLee/16128f844bfb476eb21c to your computer and use it in GitHub Desktop.
This file contains 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
/*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
commented
Jun 27, 2014
- Good job!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment