Created
February 10, 2013 20:35
-
-
Save charlespunk/4750962 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
Write code to remove duplicates from an unsorted linked list. | |
FOLLOW UP | |
How would you solve this problem if a temporary buffer is not allowed? |
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 void removeDuplicateNode(Node root){ | |
while(root != null){ | |
Node thisNode = root; | |
while(thisNode.next != null){ | |
if(thisNode.next.data == root.data) thisNode.next = thisNode.next.next; | |
//be careful of this 'else' | |
else thisNode = thisNode.next; | |
} | |
root = root.next; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment