Last active
January 28, 2016 15:44
-
-
Save berkayk/12c77928745b87307ff3 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
class Node { | |
Node next = null; | |
char data; | |
public Node(char c) { | |
data = c; | |
} | |
} | |
// FOLLOW UP -> FOLW UP | |
public Node removeDuplicates(Node head) { | |
if (head == null) | |
return null; | |
Node current = head; | |
Node prev = head; | |
// Ask if ASCII | |
boolean[] seen = new boolean[256]; | |
while (current != null) { | |
if (! seen[current.data]) { | |
seen[current.data] = true; | |
} | |
else { | |
prev.next = current.next; // skip current | |
} | |
prev = current; | |
current = current.next; | |
} | |
return head; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment