class Solution {
public int[] findEvenNumbers(int[] digits) {
List<Integer> list=new ArrayList<>();
for (int i = 0; i < digits.length; i++) {
for (int j = 0; j < digits.length; j++) {
for (int k = 0; k < digits.length; k++) {
if (i!=j && j!=k && i!=k){
int num=digits[i]*100 + digits[j] *10 +digits[k];
if (!list.contains(num)&& isAccept(digits,num)){
list.add(num);
}
}
}
}
}
List<Integer> collect = list.stream().sorted(new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
return o1 - o2;
}
}).collect(Collectors.toList());
int[] res = collect.stream().mapToInt(Integer::intValue).toArray();
return res;
}
private boolean isAccept(int[] digits, int num) {
if (num<100 || num%2!=0) {
return false;
}
return true;
}
}
Finding 3-Digit Even Numbers
最新推荐文章于 2023-03-10 17:44:16 发布