当前位置:网站首页>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;
}边栏推荐
- [exercise-5] (UVA 839) not so mobile (balance)
- Truck History
- 【练习-6】(PTA)分而治之
- Differential (one-dimensional, two-dimensional, three-dimensional) Blue Bridge Cup three body attack
- Penetration test (2) -- penetration test system, target, GoogleHacking, Kali tool
- Research Report on surgical fluid treatment industry - market status analysis and development prospect prediction
- Borg Maze (BFS+最小生成树)(解题报告)
- 【练习4-1】Cake Distribution(分配蛋糕)
- Borg maze (bfs+ minimum spanning tree) (problem solving report)
- D - Function(HDU - 6546)女生赛
猜你喜欢

b站 实时弹幕和历史弹幕 Protobuf 格式解析

【高老师UML软件建模基础】20级云班课习题答案合集

PySide6 信号、槽
![[exercise-4] (UVA 11988) broken keyboard = = (linked list)](/img/59/78ca7170ab1fd364ec44cfbcdc7ab5.png)
[exercise-4] (UVA 11988) broken keyboard = = (linked list)

Information security - threat detection - Flink broadcast stream broadcaststate dual stream merging application in filtering security logs

渗透测试 ( 2 ) --- 渗透测试系统、靶机、GoogleHacking、kali工具

Borg Maze (BFS+最小生成树)(解题报告)

Information security - Analysis of security orchestration automation and response (soar) technology

Analysis of protobuf format of real-time barrage and historical barrage at station B

用C语言写网页游戏
随机推荐
栈的经典应用—括号匹配问题
【高老师软件需求分析】20级云班课习题答案合集
【练习-10】 Unread Messages(未读消息)
Determine the Photo Position
0-1 knapsack problem (I)
STM32 how to use stlink download program: light LED running light (Library version)
Opencv learning log 16 paperclip count
Research Report of exterior wall insulation system (ewis) industry - market status analysis and development prospect prediction
Data storage in memory & loading into memory to make the program run
Interval sum ----- discretization
Alice and Bob (2021牛客暑期多校训练营1)
Record of force deduction and question brushing
1010 things that college students majoring in it must do before graduation
快速转 TypeScript 指南
[exercise-6] (UVA 725) division = = violence
[exercise -11] 4 values why sum is 0 (and 4 values of 0)
nodejs爬虫
Ball Dropping
SSM框架常用配置文件
Research Report on surgical fluid treatment industry - market status analysis and development prospect prediction