작심삼일

[LeetCode] 1689 | Partitioning Into Minimum Number of Deci-Binary Numbers | Python 본문

스터디/코테

[LeetCode] 1689 | Partitioning Into Minimum Number of Deci-Binary Numbers | Python

yun_s 2022. 6. 27. 10:30
728x90
반응형

문제 링크: 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.


조건

  • 1 <= n.length <= $10^5$
  • n consists of only digits.
  • n does not contain any leading zeros and represents a positive integer.

내 풀이

각 자리의 숫자의 크기만큼 1이 필요하다.

예를들면, 323=111+111+101이다.

그렇기때문에 가장 큰 자릿수를 리턴하면 된다.


코드

class Solution:
    def minPartitions(self, n: str) -> int:
        return max(n)
728x90
반응형
Comments