LinkedList i=a; //a contains the nodes which are adjacent to the last element of g
for(String i1: i )
{
if(g.contains(i1) || i1.equals("o"))
{ continue; }
g.addLast(i1);
func(g);
g.removeLast();
}
因此,通过它看起来好像步骤如下:
1)检查当前字符串是否存在或者它是否等于“o”
2a)如果是,则继续
2b)否则将当前字符串放在列表的末尾。
3) 重复步骤 1->2
4) 删除列表的最后一个元素
如果考虑到这些步骤,我要使代码尽可能简单,它看起来像这样:
func(LinkedList ll)
{
Set set = new HashSet(ll); //removes all duplicates
if(set.contains("o") { set.remove("o") ;} //these are strings so that works
LinkedList newLL = new LinkedList(set); //order still retained
newLL.poll(); //remove last element
}