๋ฌธ์ (์ถ์ฒ: https://www.acmicpc.net/problem/17599)
< Bags >
๋ฌธ์ ํ์ด
HashSet์ ์ฌ์ฉํ์ฌ ๋ ์ฑ ํ๊ธฐ๋ฌผ์ ์์ ํ๊ฒ ์์งํ๋ ๋ฐ ํ์ํ ์ต์ ์ฐ๋ ๊ธฐ๋ดํฌ ์๋ฅผ ๊ตฌํ๋ค.
my solution (Java)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.StringTokenizer;
public class _17599_ { // Bags
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int n = Integer.parseInt(bf.readLine());
HashSet<Integer> set = new HashSet<>();
st = new StringTokenizer(bf.readLine());
for (int i = 0; i < n; i++) {
set.add(Integer.parseInt(st.nextToken()));
}
System.out.println(set.size());
}
}
๋ณ์)
n : ๋ ์ฑ ํ๊ธฐ๋ฌผ ์
set : ๋ ์ฑ ํ๊ธฐ๋ฌผ ์ข ๋ฅ
๋ ์ฑ ํ๊ธฐ๋ฌผ ์ n์ ์ ๋ ฅ๋ฐ๋๋ค. n๊ฐ๋งํผ ๋ ์ฑ ํ๊ธฐ๋ฌผ์ ์๋ณ์๋ฅผ ์ ๋ ฅ๋ฐ์ HashSet์ ์ ์ฅํ๋ค. ์ต์ข HashSet์ ํฌ๊ธฐ๋ฅผ ์ถ๋ ฅํ๋ค.

'๐Algorithm > ๐ฅBaekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Baekjoon] 12723_Minimum Scalar Product (Small) (0) | 2025.03.11 |
---|---|
[Baekjoon] 24155_ๅพ็น (Score) (0) | 2025.03.10 |
[Baekjoon] 5092_Air Old Zeeland (0) | 2025.02.27 |
[Baekjoon] 8975_PJESMA (0) | 2025.02.26 |
[Baekjoon] 14534_String Permutation (0) | 2025.02.25 |