문제를 이해하고 있다면 바로 풀이를 보면 됨
전체 코드로 바로 넘어가도 됨
마음대로 번역해서 오역이 있을 수 있음
정수 배열 digits이 주어지고, 각 요소는 숫자이다. 배열은 중복을 포함할 수 있다.
주어진 조건을 만족하는 모든 고유한 정수를 찾아라.
예를 들어, digits이 [1, 2, 3]이 주어졌을 때, 정수 132와 312는 조건을 만족한다.
고유한 정수의 배열을 정렬해서 반환해라.
#1
Input: digits = [2, 1, 3, 0]
Output: [102, 120, 130, 132, 210, 230, 302, 310, 312, 320]
#2
Input: digits = [2, 2, 8, 8, 2]
Output: [222, 228, 282, 288, 822, 828, 882]
#3
Input: digits = [3, 7, 5]
Output: []
class Solution {
public int[] findEvenNumbers(int[] digits) {
int[] nums = new int[10];
for(int digit : digits){
nums[digit]++;
}
List<Integer> result = new ArrayList<>();
for(int i = 1; i <= 9; i++){
if(nums[i] == 0){
continue;
}
nums[i]--;
for(int j = 0; j <= 9; j++){
if(nums[j] == 0){
continue;
}
nums[j]--;
for(int k = 0; k <= 8; k += 2){
if(nums[k] == 0){
continue;
}
result.add(i * 100 + j * 10 + k);
}
nums[j]++;
}
nums[i]++;
}
return result.stream().mapToInt(Integer::intValue).toArray();
}
}