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
- string
- Tree
- array
- sorting
- Counting
- Class
- Number Theory
- 자바
- 코딩테스트
- Math
- java
- 코테
- implement
- simulation
- SQL
- 구현
- Matrix
- greedy
- hash table
- dynamic programming
- geometry
- Method
- Binary Tree
- bit manipulation
- Stack
- database
- 파이썬
- Data Structure
- two pointers
- Binary Search
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 1217. Minimum Cost to Move Chips to The Same Position 본문
코딩테스트 풀이/JAVA
[LeetCode/Easy] 1217. Minimum Cost to Move Chips to The Same Position
무지맘 2023. 4. 6. 14:131. Input
1) int[] position
- i번 칩은 position[i]에 위치해있다.
2. Output
1) 아래 규칙과 같이 칩을 오른쪽(+) 또는 왼쪽(-)으로 움직일 때, 모든 칩을 한 군데로 옮기는 데 드는 최소 비용을 반환
// i번 칩을 옮기는 데 드는 비용
- +2칸 또는 -2칸 이동: 0
- +1칸 또는 -1칸 이동: 1
3. Constraint
1) 1 <= position.length <= 100
2) 1 <= position[i] <= 10^9
4. Example
Input: position = [2,2,2,3,3] -> Output: 2
5. Code
1) 첫 코드(2023/04/06)
int odd = 0, even = 0;
for(int i : position){
if(i%2==0) even++;
else odd++;
}
return Math.min(odd, even);
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 1200. Minimum Absolute Difference (0) | 2023.04.06 |
---|---|
[LeetCode/Easy] 1207. Unique Number of Occurrences (0) | 2023.04.06 |
[LeetCode/Easy] 1232. Check If It Is a Straight Line (0) | 2023.04.06 |
[LeetCode/Easy] 1128. Number of Equivalent Domino Pairs (0) | 2023.04.06 |
[LeetCode/Easy] 1160. Find Words That Can Be Formed by Characters (0) | 2023.04.06 |