Open kukyxs opened 4 years ago
提供一种更方便的方法
fun checkSameBoolean(values: MutableList<Boolean>): Boolean {
require(values.isNotEmpty()) { "List can't be empty" }
val first = values[0]
values.filterNot { it == first }.forEach { _ -> return false }
return true
}
private boolean check(List<Boolean> booleans) {
boolean first = booleans.get(0);
for (int i = 0; i < booleans.size(); i++) {
if (booleans.get(i) != first) {
return false;
}
}
return true;
}
写出来发现和楼上一样 kotlin简洁些
目前我的思路是通过for循环进行判断,大家有其他想法也可以提出来: 代码如下: