当前位置:网站首页>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 grants the user the operation permission of the specified content
- Pyside6 signal, slot
- 【高老师软件需求分析】20级云班课习题答案合集
- b站 实时弹幕和历史弹幕 Protobuf 格式解析
- Essai de pénétration (1) - - outils nécessaires, navigation
- 1010 things that college students majoring in it must do before graduation
- 【练习-2】(Uva 712) S-Trees (S树)
- 渗透测试 ( 2 ) --- 渗透测试系统、靶机、GoogleHacking、kali工具
- Auto. Getting started with JS
- 用C语言写网页游戏
猜你喜欢
Pyside6 signal, slot
D - function (HDU - 6546) girls' competition
Information security - Analysis of security orchestration automation and response (soar) technology
Borg maze (bfs+ minimum spanning tree) (problem solving report)
树莓派4B安装opencv3.4.0
STM32 learning record: LED light flashes (register version)
差分(一维,二维,三维) 蓝桥杯三体攻击
信息安全-威胁检测-flink广播流BroadcastState双流合并应用在过滤安全日志
Determine the Photo Position
基于web的照片数码冲印网站
随机推荐
Programmers, what are your skills in code writing?
[exercise-7] crossover answers
Analyse du format protobuf du rideau en temps réel et du rideau historique de la station B
Truck History
渗透测试 2 --- XSS、CSRF、文件上传、文件包含、反序列化漏洞
Vs2019 initial use
Gartner:关于零信任网络访问最佳实践的五个建议
Nodejs+vue网上鲜花店销售信息系统express+mysql
frida hook so层、protobuf 数据解析
Opencv learning log 15 count the number of solder joints and output
[exercise-2] (UVA 712) s-trees
1010 things that college students majoring in it must do before graduation
对iptables进行常规操作
[exercise-3] (UVA 442) matrix chain multiplication
Opencv learning log 16 paperclip count
Truck History
区间和------离散化
Matlab comprehensive exercise: application in signal and system
HDU - 6024 building shops (girls' competition)
【练习4-1】Cake Distribution(分配蛋糕)