[코테 풀이] Partitioning Into Minimum Number Of Deci-Binary Numbers

시내·2024년 6월 14일

Q_1689) Partitioning Into Minimum Number Of Deci-Binary Numbers

출처 : https://leetcode.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/

A decimal number is called deci-binary if each of its digits is either 0 or 1 without any leading zeros. For example, 101 and 1100 are deci-binary, while 112 and 3001 are not.

Given a string n that represents a positive decimal integer, return the minimum number of positive deci-binary numbers needed so that they sum up to n.

class Solution {
    public int minPartitions(String n) {
        int max = -1;
        for(int i = 0; i < n.length(); i++){
            int num = n.charAt(i)-'0';
            
            if(num > max){
                max = n.charAt(i)-'0';
            }
        }
        return max;
    }
}

🙈 알고리즘 풀이 참조한 문제
결국엔 n 에서 가장 큰 digit을 가진 게 답이 된다

profile
contact 📨 ksw08215@gmail.com

0개의 댓글