# 1689. Partitioning Into Minimum Number Of Deci-Binary Numbers ## 題目概要 給定一個字串 n,找出和為 n 的最少數量 deci-binary。 deci-binary 的定義是以 0 或 1 組成的非 0 開頭的十進制數字。 ``` Example 1: Input: n = "32" Output: 3 Explanation: 10 + 11 + 11 = 32 Example 2: Input: n = "82734" Output: 8 Example 3: Input: n = "27346209830709182346" Output: 9 ``` ## 解題技巧 - 因為要求是最少個數,所以可以推斷出每個 deci-binary 值盡量都會很大,比方說 `82734` 會是: ``` 11111 11111 10111 10101 10100 10100 10100 10000 ===== 82734 ``` 而 `7895` 就會是: ``` 1111 1111 1111 1111 1111 1110 1110 0110 0010 ==== 7895 ``` 根據此規律不難推出,我們只需要**找到 n 之中最大的數**,就可以得出 deci-binary 的最少數目。 ## 程式碼 ```javascript var minPartitions = function(n) { return Math.max(...n.split('')); }; ``` 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up