반응형
Notice
Recent Posts
Recent Comments
- Today
- Total
작심삼일
[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:30728x90
반응형
문제 링크: 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
반응형
'스터디 > 코테' 카테고리의 다른 글
[LeetCode] 406 | Queue Reconstruction by Height | Python (0) | 2022.06.29 |
---|---|
[LeetCode] 1647 | Minimum Deletions to Make Character Frequencies Unique | Python (0) | 2022.06.28 |
[630] 630 | Course Schedule III | Python (0) | 2022.06.23 |
[LeetCode] 215 | Kth Largest Element in an Array | Python (0) | 2022.06.22 |
[LeetCode] 820 | Short Encoding of Words | Python (0) | 2022.06.20 |
Comments