当前位置:网站首页>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;
}
边栏推荐
- 【练习-10】 Unread Messages(未读消息)
- 信息安全-安全专业名称|CVE|RCE|POC|VUL|0DAY
- STM32 how to use stlink download program: light LED running light (Library version)
- Shell Scripting
- 【练习-6】(PTA)分而治之
- SSM框架常用配置文件
- [exercise-2] (UVA 712) s-trees
- Penetration test (8) -- official document of burp Suite Pro
- MySQL grants the user the operation permission of the specified content
- Information security - threat detection - detailed design of NAT log access threat detection platform
猜你喜欢
D - function (HDU - 6546) girls' competition
frida hook so层、protobuf 数据解析
【练习-4】(Uva 11988)Broken Keyboard(破损的键盘) ==(链表)
PySide6 信号、槽
【高老师UML软件建模基础】20级云班课习题答案合集
Record of force deduction and question brushing
D - Function(HDU - 6546)女生赛
洛谷P1102 A-B数对(二分,map,双指针)
[exercise-7] crossover answers
Information security - Analysis of security orchestration automation and response (soar) technology
随机推荐
【高老师软件需求分析】20级云班课习题答案合集
C basic grammar
Auto. Getting started with JS
frida hook so层、protobuf 数据解析
树莓派4B安装opencv3.4.0
Research Report of peripheral venous catheter (pivc) industry - market status analysis and development prospect prediction
X-Forwarded-For详解、如何获取到客户端IP
Ball Dropping
Borg maze (bfs+ minimum spanning tree) (problem solving report)
滲透測試 ( 1 ) --- 必備 工具、導航
Optimization method of path problem before dynamic planning
Auto.js入门
【练习-4】(Uva 11988)Broken Keyboard(破损的键盘) ==(链表)
栈的经典应用—括号匹配问题
[exercise-7] crossover answers
信息安全-安全编排自动化与响应 (SOAR) 技术解析
E. Breaking the Wall
7-1 懂的都懂 (20 分)
b站 實時彈幕和曆史彈幕 Protobuf 格式解析
[exercise-4] (UVA 11988) broken keyboard = = (linked list)