-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathJW_132265.java
More file actions
24 lines (23 loc) Β· 1.09 KB
/
JW_132265.java
File metadata and controls
24 lines (23 loc) Β· 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.util.HashSet;
class JW_132265 {
public int solution(int[] topping) {
int answer = 0;
int len = topping.length;
// μ’
λ₯ μλ₯Ό κ³μ°νκΈ° μν Set
HashSet<Integer> setA = new HashSet<>();
HashSet<Integer> setB = new HashSet<>();
int[] typeA = new int[len]; // μλμμ μλ‘ ν νμ μλ₯Ό μ μ₯ν λ°°μ΄
int[] typeB = new int[len]; // μμμ μλλ‘ ν νμ μλ₯Ό μ μ₯ν λ°°μ΄
for (int i = 0; i < len; i++) {
setA.add(topping[i]); // μ’
λ₯ μΆκ°
setB.add(topping[len - 1 - i]); // Setμ΄κΈ°μ μ€λ³΅μ νμ©νμ§ μμ
typeA[i] = setA.size(); // iλ²μ§ΈκΉμ§μ μ’
λ₯ μλ₯Ό μ μ₯
typeB[len - 1 - i] = setB.size(); // λμμ iλ²μ§ΈκΉμ§μ μ’
λ₯ μλ₯Ό μ μ₯
}
for (int i = 0; i < len - 1; i++)
// iμ i + 1μ μ¬μ΄λ₯Ό μλλλ° μ’
λ₯μκ° κ°λ€λ©΄
if (typeA[i] == typeB[i + 1])
answer++;
return answer;
}
}