当前位置:网站首页>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;
}
边栏推荐
- 0 - 1 problème de sac à dos (1)
- The most complete programming language online API document
- frida hook so层、protobuf 数据解析
- [analysis of teacher Gao's software needs] collection of exercises and answers for level 20 cloud class
- Opencv learning log 15 count the number of solder joints and output
- Information security - security professional name | CVE | rce | POC | Vul | 0day
- D - Function(HDU - 6546)女生赛
- Penetration test (3) -- Metasploit framework (MSF)
- Nodejs+vue online fresh flower shop sales information system express+mysql
- 渗透测试 2 --- XSS、CSRF、文件上传、文件包含、反序列化漏洞
猜你喜欢
信息安全-威胁检测引擎-常见规则引擎底座性能比较
Luogu P1102 A-B number pair (dichotomy, map, double pointer)
D - Function(HDU - 6546)女生赛
Penetration test (2) -- penetration test system, target, GoogleHacking, Kali tool
Data storage in memory & loading into memory to make the program run
Analyse du format protobuf du rideau en temps réel et du rideau historique de la station B
差分(一维,二维,三维) 蓝桥杯三体攻击
渗透测试 ( 7 ) --- 漏洞扫描工具 Nessus
Information security - threat detection - Flink broadcast stream broadcaststate dual stream merging application in filtering security logs
7-1 懂的都懂 (20 分)
随机推荐
mysql导入数据库报错 [Err] 1273 – Unknown collation: ‘utf8mb4_0900_ai_ci’
D - Function(HDU - 6546)女生赛
B - Code Party (girls' competition)
[exercise-8] (UVA 246) 10-20-30== simulation
【练习-11】4 Values whose Sum is 0(和为0的4个值)
想应聘程序员,您的简历就该这样写【精华总结】
【练习-6】(Uva 725)Division(除法)== 暴力
Penetration test (3) -- Metasploit framework (MSF)
Record of brushing questions with force deduction -- complete knapsack problem (I)
PySide6 信号、槽
信息安全-安全编排自动化与响应 (SOAR) 技术解析
用C语言写网页游戏
[exercise-6] (UVA 725) division = = violence
树莓派4B安装opencv3.4.0
The most complete programming language online API document
差分(一维,二维,三维) 蓝桥杯三体攻击
双向链表—全部操作
Information security - Analysis of security orchestration automation and response (soar) technology
Nodejs+vue网上鲜花店销售信息系统express+mysql
Determine the Photo Position