Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- 자바
- Binary Search
- Matrix
- simulation
- geometry
- Class
- java
- hash table
- bit manipulation
- Counting
- 파이썬
- array
- Math
- Number Theory
- sorting
- implement
- Stack
- 코딩테스트
- SQL
- two pointers
- greedy
- Data Structure
- 코테
- 구현
- dynamic programming
- database
- Method
- Binary Tree
- string
- Tree
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 575. Distribute Candies 본문
1. Input
1) int[] candyType
- candyType[i]는 i번째 사탕의 타입을 나타낸다.
2. Output
1) n개의 사탕 중 절반만 먹을 수 있다고 할 때, 먹을 수 있는 사탕의 종류 수 중 가장 큰 것을 반환
3. Constraint
1) n == candyType.length
2) 2 <= n <= 10^4
3) n은 항상 짝수이다.
4) - 10^5 <= candyType[i] <= 10^5
4. Example
Input: candyType = [1,1,2,3] -> Output: 2
설명:
- 사탕은 4/2 = 2개 먹을 수 있고, 총 3종류가 있으므로 (1,2), (1,3), (2,3)을 먹을 수 있다. 따라서 먹을 수 있는 사탕의 종류는 최대 2종류이다.
5. Code
1) 첫 코드(2023/03/06)
HashSet<Integer> s = new HashSet<Integer>();
for(int i : candyType)
s.add(i);
return s.size()>candyType.length/2 ? candyType.length/2 : s.size();
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Medium] 2579. Count Total Number of Colored Cells (0) | 2023.03.06 |
---|---|
[LeetCode/Easy] 2578. Split With Minimum Sum (0) | 2023.03.06 |
[LeetCode/Easy] 2558. Take Gifts From the Richest Pile (0) | 2023.03.02 |
[LeetCode/Easy] 2562. Find the Array Concatenation Value (0) | 2023.03.02 |
[LeetCode/Medium] 532. K-diff Pairs in an Array (0) | 2023.03.02 |