我有一种方法可以遍历板上的可能状态并将它们存储在 HashMap 中
void up(String str){
int a = str.indexOf("0");
if(a>2){
String s = str.substring(0,a-3)+"0"+str.substring(a-2,a)+str.charAt(a-3)+str.substring(a+1);
add(s,map.get(str)+1);
if(s.equals("123456780")) {
System.out.println("The solution is on the level "+map.get(s)+" of the tree");
//If I get here, I need to know the keys on the map
// How can I store them and Iterate through them using
// map.keySet()?
}
}
}
我对这组键感兴趣。我应该怎么做才能全部打印出来?
HashSet t = map.keySet()
被编译器拒绝
LinkedHashSet t = map.keySet()