티스토리 뷰
N개의 숫자를 갖는 배열 A를 입력 받아서, 그 배열에 distinct한 숫자 수를 반환하는 문제.
// you can also use imports, for example:
import java.util.HashSet;
import java.util.Set;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
Set<Integer> set = new HashSet<>();
for (int i = 0; i < A.length; i++) {
set.add(A[i]);
}
return set.size();
}
}
간단하게 hashmap을 이용해서 모두 hashmap에 넣어주고, hashmap의 사이즈를 반환하면 됨.
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Asynchronous
- 비동기
- 필터
- Filter
- non-blocking
- 핸들러 인터셉터
- Synchronous
- 코딩테스트 고득점 Kit
- 프로그래머스 Level 3
- 프로그래머스
- a
- 스택/큐
- 프로그래머스 Level 2
- 논블로킹
- 동기
- 프로그래머스 Level 1
- Handler Interceptor
- 해시
- 인터셉터
- blocking
- 블로킹
- http://www.nextree.co.kr/p6960/
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
글 보관함