【发布时间】:2020-05-05 06:13:43
【问题描述】:
所以我用谷歌搜索了这个问题。只有这个来自 StackOF 的链接出现了。 The question is ~4 years old.
我发现我的解决方案相当简单,但没有人写过,这有意义吗?
代码如下:
public boolean areAllTheSame(int[][] image) {
// Create a new set, so we can store our unique elems there.
Set<Integer> set = new HashSet<>();
//Iterate through all elements, add to our HashSet set
for (int[] ints : image) {
for (int anInt : ints) {
set.add(anInt);
}
}
// Because set has only unique elements, if all are the same => size should be 1
return set.size() == 1;
} // end of areAllTheSame
【问题讨论】:
标签: java arrays multidimensional-array 2d