当前位置:网站首页>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;
}边栏推荐
- Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools
- Gartner:关于零信任网络访问最佳实践的五个建议
- Ball Dropping
- Determine the Photo Position
- Information security - threat detection engine - common rule engine base performance comparison
- 渗透测试 ( 1 ) --- 必备 工具、导航
- Penetration test (1) -- necessary tools, navigation
- Opencv learning log 13 corrosion, expansion, opening and closing operations
- STM32 learning record: LED light flashes (register version)
- Information security - Epic vulnerability log4j vulnerability mechanism and preventive measures
猜你喜欢

Analyse du format protobuf du rideau en temps réel et du rideau historique de la station B

树莓派4B安装opencv3.4.0

X-Forwarded-For详解、如何获取到客户端IP

The concept of C language array

Pyside6 signal, slot

TCP's three handshakes and four waves

Essai de pénétration (1) - - outils nécessaires, navigation

Record of force deduction and question brushing

Data storage in memory & loading into memory to make the program run

Programmers, what are your skills in code writing?
随机推荐
HDU - 6024 building shops (girls' competition)
JS call camera
B - Code Party (girls' competition)
China potato slicer market trend report, technical dynamic innovation and market forecast
Truck History
VS2019初步使用
Record of brushing questions with force deduction -- complete knapsack problem (I)
[exercise-7] (UVA 10976) fractions again?! (fraction split)
[exercise-6] (UVA 725) division = = violence
Research Report on market supply and demand and strategy of China's earth drilling industry
Analyse du format protobuf du rideau en temps réel et du rideau historique de la station B
Data storage in memory & loading into memory to make the program run
Research Report on shell heater industry - market status analysis and development prospect forecast
[exercise-9] Zombie's Treasury test
Penetration test (7) -- vulnerability scanning tool Nessus
STM32 learning record: LED light flashes (register version)
If you want to apply for a programmer, your resume should be written like this [essence summary]
B - 代码派对(女生赛)
Auto. Getting started with JS
Penetration test (4) -- detailed explanation of meterpreter command