Skip to content

Instantly share code, notes, and snippets.

@berkayk
Last active January 28, 2016 15:44
Show Gist options
  • Save berkayk/12c77928745b87307ff3 to your computer and use it in GitHub Desktop.
Save berkayk/12c77928745b87307ff3 to your computer and use it in GitHub Desktop.
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