架构师训练营第八周作业 - 命题作业
package com.example.demo;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class Test {
@org.junit.Test
public void contextLoads() {
//模拟两个单项链表
LinkedList<Object> list1=new LinkedList<Object>();
LinkedList<Object> list2=new LinkedList<Object>();
Iterator<Object> iterator1=list1.iterator();
Iterator<Object> iterator2=list2.iterator();
HashSet<Object> set=new HashSet<Object>();
//链表 1 遍历,放入 set 当中
while(iterator1.hasNext()) {
Object obj=iterator1.next();
set.add(obj);
}
//链表 2 遍历,查找合并点
while(iterator2.hasNext()) {
Object obj=iterator2.next();
if(set.contains(obj)) {
//找到合并点
}
}
}
}
评论