Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bitcpf
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitcpf/7ce6a0976d775bd00724 to your computer and use it in GitHub Desktop.
Save bitcpf/7ce6a0976d775bd00724 to your computer and use it in GitHub Desktop.
CC_2_1
/*
Created by bitcpf
*/
import java.util.*;
public class Removedup {
public static <Item> LinkedList<Item> Rmdup(LinkedList<Item> in_link){
HashSet<Item> set = new HashSet<Item>();
LinkedList<Item> newlist = new LinkedList<Item>();
for(Item item: in_link){
if(set.add(item)){
newlist.add(item);
}
}
return newlist;
}
public static void main(String[] args){
LinkedList<Integer> testcase = new LinkedList<Integer>();
testcase.add(1);
testcase.add(3);
testcase.add(5);
testcase.add(6);
testcase.add(4);
testcase.add(2);
testcase.add(3);
testcase.add(2);
System.out.println(testcase.toString());
System.out.println(Rmdup(testcase).toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment