[코테 풀이] Minimum Sum of Four Digit Number After Splitting Digits

시내·2024년 6월 12일
0

Q_2160) Minimum Sum of Four Digit Number After Splitting Digits

출처 : https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits/

class Solution {
    public int minimumSum(int num) {
        
        ArrayList<Character> array = new ArrayList<>();
        for (int i = 0; i < Integer.toString(num).length(); i++) {
            array.add(Integer.toString(num).charAt(i));
        }
        Collections.sort(array);
        int one = (array.get(0) - '0') * 10 + (array.get(2) - '0');
        int two = (array.get(1) - '0') * 10 + (array.get(3) - '0');
        return one + two;
    }
}
profile
contact 📨 ksw08215@gmail.com

0개의 댓글