当前位置:网站首页>1903. Maximum odd number in string
1903. Maximum odd number in string
2022-07-06 16:07:00 【mrbone9】
Address :
Power button https://leetcode-cn.com/problems/largest-odd-number-in-string/submissions/
subject :
Give you a string num , Represents a large integer . Please write in the string num All of the Non empty substring To find out in the The odd number with the largest value , And returns... As a string . If there is no odd number , Then return an empty string "" .
Substring Is a continuous sequence of characters in a string .
Example 1:
Input :num = "52" Output :"5" explain : Non empty substrings have only "5"、"2" and "52" ."5" It's the only odd number . |
Example 2:
Input :num = "4206" Output :"" explain : stay "4206" There is no odd number in . |
Example 3:
Input :num = "35427" Output :"35427" explain :"35427" It's an odd number in itself . |
Tips :
1 <= num.length <= 105 num Composed of numbers only and without leading zeros |
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/largest-odd-number-in-string
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Ideas :
Odd number means that a bit is odd , As for the biggest , That is to regard the previous numbers as one ( If there is a previous number )
So the topic is very simple , Find odd numbers in reverse order , If you find that , Just copy forward
Method 1 、 Find the position where odd numbers appear in reverse order
char odd[100001];
char * largestOddNumber(char * num){
int slen = strlen(num);
memset(odd, 0, sizeof(char));
odd[105] = '\0';
for(int i=slen-1, j=0; i>=0; i--, j++)
{
int ch = num[i] - '0';
if(ch & 1)
{
strncpy(odd, num, slen - j);
odd[slen-j]='\0';
break;
}
}
return odd;
}
边栏推荐
- MySQL授予用户指定内容的操作权限
- HDU-6025-Coprime Sequence(女生赛)
- Web based photo digital printing website
- 7-1 understand everything (20 points)
- 【高老师UML软件建模基础】20级云班课习题答案合集
- Programmers, what are your skills in code writing?
- Opencv learning log 33 Gaussian mean filtering
- F - Birthday Cake(山东省赛)
- 【高老师软件需求分析】20级云班课习题答案合集
- Pyside6 signal, slot
猜你喜欢
洛谷P1102 A-B数对(二分,map,双指针)
树莓派4B安装opencv3.4.0
Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools
Information security - Epic vulnerability log4j vulnerability mechanism and preventive measures
MySQL import database error [err] 1273 - unknown collation: 'utf8mb4_ 0900_ ai_ ci’
Programmers, what are your skills in code writing?
渗透测试 2 --- XSS、CSRF、文件上传、文件包含、反序列化漏洞
Analyse du format protobuf du rideau en temps réel et du rideau historique de la station B
Penetration test (4) -- detailed explanation of meterpreter command
C language must memorize code Encyclopedia
随机推荐
Interesting drink
Write web games in C language
Analyse du format protobuf du rideau en temps réel et du rideau historique de la station B
Research Report of exterior wall insulation system (ewis) industry - market status analysis and development prospect prediction
China exterior wall cladding (EWC) market trend report, technical dynamic innovation and market forecast
SSM框架常用配置文件
滲透測試 ( 1 ) --- 必備 工具、導航
CS zero foundation introductory learning record
Perform general operations on iptables
【练习-6】(Uva 725)Division(除法)== 暴力
Shell Scripting
[exercise-8] (UVA 246) 10-20-30== simulation
差分(一维,二维,三维) 蓝桥杯三体攻击
洛谷P1102 A-B数对(二分,map,双指针)
双向链表—全部操作
Nodejs crawler
[exercise-2] (UVA 712) s-trees
Understand what is a programming language in a popular way
F - Birthday Cake(山东省赛)
Matlab comprehensive exercise: application in signal and system