Created
January 11, 2019 05:05
-
-
Save scaffeinate/0bfcd768d770a186627db2f18894a060 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 static SinglyLinkedListNode removeNodes(SinglyLinkedListNode listHead, int x) { | |
SinglyLinkedListNode head = null, tail = null; | |
while (listHead != null) { | |
if (listHead.data <= x) { | |
SinglyLinkedListNode node = new SinglyLinkedListNode(); | |
node.data = listHead.data; | |
if(head == null) { | |
head = tail = node; | |
} else { | |
tail.next = node; | |
tail = node; | |
} | |
} | |
listHead = listHead.next; | |
} | |
return head; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
`public static SinglyLinkedListNode removeNodes(SinglyLinkedListNode listHead, int x) {
SinglyLinkedListNode head = null, tail = null;
while (listHead != null) {
if (listHead.data <= x) {
SinglyLinkedListNode node = new SinglyLinkedListNode(x);
node.data = listHead.data;
if(head == null) {
head = tail = node;
} else {
tail.next = node;
tail = node;
}
}
}`