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
}