50,528
社区成员
发帖
与我相关
我的任务
分享
import cn.hutool.json.JSONUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Test {
public static void main(String[] args) {
Integer[][] aa = new Integer[][]{{1,5,7,9},{2,4,5,9 },{2,3,5,7 },{2,3,5,7 },{2,6,7,9 },{4,6,8,9 },{2,3,5,7 },{2,6,7,9 },{2,6,7,9 }};
Integer[] pre = null;
List<Integer[]> list = new ArrayList<>();
for (Integer[] a:aa) {
if (pre != null){
if (JSONUtil.toJsonStr(pre).equals(JSONUtil.toJsonStr(a))){
//与上一个相同
} else {
list.add(a);
}
} else {
list.add(a);
}
pre = a;
}
int index = 0;
Map<String,Integer> map = new HashMap<>();
System.out.println(JSONUtil.toJsonStr(list));
for (Integer[] a:list ) {
Integer integer = map.get(JSONUtil.toJsonStr(a));
if (integer == null){
map.put(JSONUtil.toJsonStr(a),7-++index);
} else {
map.put(JSONUtil.toJsonStr(a),integer - 7 + index );
index++;
}
}
System.out.println(JSONUtil.toJsonStr(map));
}
}