반응형
오늘 풀 문제는 Partitioning Into Minimum Number Of Deci-Binary Numbers라는 문제이며
링크는 leetcode.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/입니다
문제는 0과1 로만 이루어지고 0으로 시작하지 않는 수를 deci-binary라고 하는데, 주어진 n을 최소한의 deci-binary 갯수의 합으로 만들고 그 최소한의 갯수를 구하는 게 답입니다!
저는 string n에 최대 숫자가 있으면 1이 그 최대 숫자만큼은 있어야하니까 그만큼의 갯수는 필요하다고 생각하였습니다.
따라서 string n에 포함되어있는 최대값을 구하였습니다
코드는 아래와 같습니다
func minPartitions(n string) int {
res := 1;
for _, char := range n {
num := int(char) - 48;
if(res < num){
res = num;
}
}
return res;
}
감사합니다!
'Language > Go' 카테고리의 다른 글
[Golang으로 도전하는 Leetcode] Count of Matches in Tournament (0) | 2020.12.16 |
---|---|
[Golang으로 도전하는 Leetcode] Max Number of K-Sum Pairs (0) | 2020.12.12 |
[Golang으로 도전하는 Leetcode] Goal Parser Interpretation (0) | 2020.12.09 |
[Golang으로 도전하는 Leetcode] Goal Parser Interpretation (0) | 2020.12.09 |
[Golang으로 도전하는 Leetcode] Richest Customer Wealth (0) | 2020.12.04 |