2.1 创建linkedlist hashset node
来源:互联网 发布:手机用windows系统 编辑:程序博客网 时间:2024/06/02 01:58
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?
soln: 还有就是快指针慢指针,不说了
package test;
import java.util.Scanner;
import java.util.HashSet;
public class JumpTwo {
static class Node {
char data;
Node next = null;
Node(char a) {
this.data = a;
}
}
public static void main(String[] args) {
Egg egg = new Egg();
Scanner input = new Scanner(System.in);
StringBuffer sb = new StringBuffer(input.nextLine());
String s = sb.toString();
char[] chars = s.toCharArray();
Node p = new Node('1');
Node head = p;
for (char c : chars) {
p.next = new Node(c);
p = p.next;
}
head = head.next;
removeDup(head);
while (null != head){
System.out.println(head.data);
head = head.next;
}
}
private static void removeDup(Node head) {
HashSet<Character> elem = new HashSet<Character>();
Node cur = head.next;
Node pre = head;
elem.add(head.data);
while (cur != null) {
if (elem.contains(cur.data)) {
pre.next = cur.next;
cur = null;
cur = pre.next;
} else {
elem.add(cur.data);
pre = cur;
cur = cur.next;
}
}
}
}
0 0
- 2.1 创建linkedlist hashset node
- LinkedList HashSet
- 集合 LinkedList、Hashset、TreeSet --基础
- ArrayList、LinkedList和HashSet、…
- HashSet、HashMap、ArrayList、LinkedList、Vector
- ArrayList、LinkedList、HashSet以及HashMap
- 集合( LinkedList,HashSet,Collection ) 总结
- LinkedList、HashSet、Collection集合体系
- 总结:集合框架(LinkedList,ArrayList,HashSet)
- HashSet TreeSet LinkedList ArrayList Hashmap Treemap
- (Leetcode)46&47 Permutations--LinkedList and HashSet
- HashSet、HashMap、ArrayList、LinkedList、Vector区别
- Java集合框架-LinkedList和HashSet
- day08-集合【LinkedList、HashSet、Collection集合体系】
- 详解ArrayList、LinkedList、Hashtable、HashMap、HashSet
- Copy LinkedList With Arbitrary Node
- Delete Node In A LinkedList
- array数组,arraylist,hashset,vector,linkedlist,速度对比。
- 黑马程序员-List-ListIterator-LinkedList-ArrayList
- HDU 2094 -- 产生冠军 (邻接表或直接比较)
- linux selinux对于ftp的控制
- linux系统内核UDP丢包原因分析
- jni问题备忘
- 2.1 创建linkedlist hashset node
- QT中静态库的生成与使用
- QT链接库中类的导出,以及使用
- 开始
- GTK入门学习:一个简单的空白窗口
- RMQ算法
- CentOS 6.5安装配置SVN
- ffmpeg学习记录
- Leetcode NO.153 Find Minimum in Rotated Sorted Array