当前位置:网站首页>1689. Ten - the minimum number of binary numbers
1689. Ten - the minimum number of binary numbers
2022-07-06 16:07:00 【mrbone9】
Address :
subject :
If a decimal number does not contain any leading zeros , And the number on each bit is not 0 Namely 1 , So the number is a Ten - Binary number . for example ,101 and 1100 All are Ten - Binary number , and 112 and 3001 No .
Here's a string for decimal integers n , Return and for n Of Ten - Binary number The minimum number of .
Example 1:
Input :n = "32" Output :3 explain :10 + 11 + 11 = 32 |
Example 2:
Input :n = "82734" Output :8 |
Example 3:
Input :n = "27346209830709182346" Output :9 |
Tips :
1 <= n.length <= 105 n It's just numbers n Does not contain any leading zeros and always represents a positive integer |
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Ideas :
Example :82734
Representation of decimal numbers :
8*10^4 + 2*10^3 + 7*10^2 + 3*10^1 + 4*10^0
10000 | 1000 | 100 | 10 | 1 |
10000 | 1000 | 100 | 10 | 1 |
10000 | 100 | 10 | 1 | |
10000 | 100 | 1 | ||
10000 | 100 | |||
10000 | 100 | |||
10000 | 100 | |||
10000 |
Let's take another example :32
10 | 1 |
10 | 1 |
10 |
These two examples , For each line, it is a combined number , There can only be one on the same bit
In this case , For bits , The longest number is the maximum number of rows that can be combined , That is, the minimum number that can be split
otherwise , such as 100, You can continue to split , The number is more
So this question is to find the largest number in a group of numbers
Method 1 、 Traverse to find the maximum number
int minPartitions(char * n){
int slen = strlen(n);
char max = '0';
int i = 0;
while(n[i])
{
if(max < n[i])
max = n[i];
i++;
}
return max - '0';
}
边栏推荐
- 渗透测试 ( 1 ) --- 必备 工具、导航
- Luogu P1102 A-B number pair (dichotomy, map, double pointer)
- China exterior wall cladding (EWC) market trend report, technical dynamic innovation and market forecast
- 栈的经典应用—括号匹配问题
- 渗透测试 ( 7 ) --- 漏洞扫描工具 Nessus
- What is the difficulty of programming?
- Opencv learning log 28 -- detect the red cup cover
- MySQL授予用户指定内容的操作权限
- Basic Q & A of introductory C language
- Auto.js入门
猜你喜欢
Determine the Photo Position
Gartner:关于零信任网络访问最佳实践的五个建议
Penetration test (7) -- vulnerability scanning tool Nessus
Ball Dropping
7-1 懂的都懂 (20 分)
Penetration test (4) -- detailed explanation of meterpreter command
Information security - threat detection - Flink broadcast stream broadcaststate dual stream merging application in filtering security logs
1010 things that college students majoring in it must do before graduation
Vs2019 initial use
渗透测试 ( 3 ) --- Metasploit Framework ( MSF )
随机推荐
【练习-2】(Uva 712) S-Trees (S树)
E. Breaking the Wall
Frida hook so layer, protobuf data analysis
Penetration test (2) -- penetration test system, target, GoogleHacking, Kali tool
渗透测试 ( 7 ) --- 漏洞扫描工具 Nessus
Pyside6 signal, slot
信息安全-威胁检测-flink广播流BroadcastState双流合并应用在过滤安全日志
Analysis of protobuf format of real-time barrage and historical barrage at station B
【练习-9】Zombie’s Treasure Chest
Nodejs+vue online fresh flower shop sales information system express+mysql
Borg Maze (BFS+最小生成树)(解题报告)
[exercise-1] (UVA 673) parentheses balance/ balanced brackets (stack)
Understand what is a programming language in a popular way
PySide6 信号、槽
[exercise-7] (UVA 10976) fractions again?! (fraction split)
STM32 learning record: LED light flashes (register version)
Penetration test (1) -- necessary tools, navigation
JS调用摄像头
Basic Q & A of introductory C language
渗透测试 ( 8 ) --- Burp Suite Pro 官方文档