Created
February 24, 2014 23:05
-
-
Save rayjcwu/9199162 to your computer and use it in GitHub Desktop.
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
| public Node removeNode(Node head, int val) { | |
| Node fakeHead = new Node(0); | |
| Node tail = fakeHead; | |
| while (head != null) { | |
| if (head.val != val) { | |
| tail.next = head; | |
| tail = tail.next; | |
| } | |
| head = head.next; | |
| } | |
| tail.next = null; | |
| return fakeHead.next; | |
| } | |
| public NOde removeNode(Node node, int val) { | |
| if (node == null) { | |
| return null; | |
| } else if (node.val == val) { | |
| return removeNode(node.next, val); | |
| } else { | |
| node.next = removeNode(node.next, val); | |
| return node; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment