当前位置:网站首页>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;
}
边栏推荐
- 【练习-11】4 Values whose Sum is 0(和为0的4个值)
- Alice and Bob (2021牛客暑期多校训练营1)
- [exercise 4-1] cake distribution
- 渗透测试 ( 3 ) --- Metasploit Framework ( MSF )
- Common configuration files of SSM framework
- 滲透測試 ( 1 ) --- 必備 工具、導航
- Opencv learning log 30 -- histogram equalization
- 0 - 1 problème de sac à dos (1)
- HDU - 6024 building shops (girls' competition)
- MySQL授予用户指定内容的操作权限
猜你喜欢
Ball Dropping
X-Forwarded-For详解、如何获取到客户端IP
Penetration test (8) -- official document of burp Suite Pro
STM32 learning record: LED light flashes (register version)
Gartner: five suggestions on best practices for zero trust network access
Basic Q & A of introductory C language
Penetration test (3) -- Metasploit framework (MSF)
Differential (one-dimensional, two-dimensional, three-dimensional) Blue Bridge Cup three body attack
Borg Maze (BFS+最小生成树)(解题报告)
Penetration test (1) -- necessary tools, navigation
随机推荐
【练习-10】 Unread Messages(未读消息)
[exercise-8] (UVA 246) 10-20-30== simulation
New to redis
Information security - security professional name | CVE | rce | POC | Vul | 0day
双向链表—全部操作
【练习-1】(Uva 673) Parentheses Balance/平衡的括号 (栈stack)
信息安全-安全专业名称|CVE|RCE|POC|VUL|0DAY
Analysis of protobuf format of real-time barrage and historical barrage at station B
【练习-6】(PTA)分而治之
C language must memorize code Encyclopedia
Analyse du format protobuf du rideau en temps réel et du rideau historique de la station B
7-1 懂的都懂 (20 分)
Information security - Analysis of security orchestration automation and response (soar) technology
信息安全-史诗级漏洞Log4j的漏洞机理和防范措施
树莓派CSI/USB摄像头使用mjpg实现网页摄像头监控
STM32 learning record: LED light flashes (register version)
[exercise-9] Zombie's Treasury test
Alice and Bob (2021 Niuke summer multi school training camp 1)
Hdu-6025-prime sequence (girls' competition)
【高老师软件需求分析】20级云班课习题答案合集