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 Tree
- 파이썬
- sorting
- Counting
- greedy
- 코딩테스트
- bit manipulation
- Number Theory
- Stack
- simulation
- database
- Method
- string
- 코테
- Data Structure
- array
- 자바
- implement
- Tree
- Math
- hash table
- java
- geometry
- dynamic programming
- Matrix
- two pointers
- 구현
- Binary Search
- SQL
- Class
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 2160. Minimum Sum of Four Digit Number After Splitting Digits 본문
코딩테스트 풀이/JAVA
[LeetCode/Easy] 2160. Minimum Sum of Four Digit Number After Splitting Digits
무지맘 2023. 1. 13. 21:521. Input
1) 4자리 자연수 num
2. Output
1) num의 숫자 4개를 나눠서 2개의 숫자를 만들었을 때, 두 수의 합의 최솟값
3. Constraint
1) 1000 <= num <= 9999
4. Example
Input: num = 2932 -> Output: 52
설명: 2932를 2개의 숫자로 나누면 [22, 93], [22, 39], [23, 29], [23, 92], [223, 9], [2, 329] 등의 여러 숫자들이 나오는데, 이 중 합이 가장 작을 때는 [23, 29]이며, 합은 52이다.
5. Code
1) 첫 코드(2022/07/01)
import java.util.*;
int[] n = new int[4];
for(int i=0 ; i<4 ; i++){
n[i] = num%10;
num /= 10;
}
Arrays.sort(n);
return (n[0]+n[1])*10 + n[2] + n[3];