Skip to content

Latest commit

 

History

History
45 lines (29 loc) · 758 Bytes

File metadata and controls

45 lines (29 loc) · 758 Bytes

1689. Partitioning Into Minimum Number Of Deci-Binary Numbers

Leetcode link

解题思路

题目要求我们使用二进制的数来拼出十进制的任何数


本题答案个数的限制在于给出的十进制数最大的一位数,所以我们只要遍历找出最大的那个元素就好

C++

class Solution {
public:
    int minPartitions(string n) {
        return *max_element(n.begin(), n.end()) - '0';
    }
};

Javascript

/**
 * @param {string} n
 * @return {number}
 */
var minPartitions = function(n) {
    let max = 0;
    for(let c of n) {
        max = Math.max(c, max);
    }
    return max;
};