当前位置:网站首页>Leetcode simple question: check whether the numbers in the sentence are increasing
Leetcode simple question: check whether the numbers in the sentence are increasing
2022-07-06 15:03:00 【·Starry Sea】
subject
The sentence consists of several token A list of ,token In between Single The blank space to separate , The sentence has no leading or trailing spaces . Every token Or a number 0-9 Consisting of... Without leading zeros Positive integer , Or it's a small English letter word .
Example ,“a puppy has 2 eyes 4 legs” It's a by 7 individual token Make up sentences :“2” and “4” It's the number. , Other images “puppy” In this way tokens Belongs to the word .
Give you a string that represents a sentence s , You need to check s Medium All Is the number strictly increasing from left to right ( namely , Except for the last number ,s Medium Every Numbers are strictly smaller than it On the right side The number of ).
If you meet the requirements of the topic , return true , otherwise , return false .
Example 1:
Input :s = “1 box has 3 blue 4 red 6 green and 12 yellow marbles”
Output :true
explain : The number in the sentence is :1, 3, 4, 6, 12 .
These numbers are strictly increasing from left to right 1 < 3 < 4 < 6 < 12 .
Example 2:
Input :s = “hello world 5 x 5”
Output :false
explain : The number in the sentence is :5, 5 . These numbers are not strictly incremental .
Example 3:
Input :s = “sunset is at 7 51 pm overnight lows will be in the low 50 and 60 s”
Output :false
explain :s The number in is :7, 51, 50, 60 . These numbers are not strictly incremental .
Example 4:
Input :s = “4 5 11 26”
Output :true
explain :s The number in is :4, 5, 11, 26 .
These numbers are strictly increasing from left to right :4 < 5 < 11 < 26 .
Tips :
3 <= s.length <= 200
s By lowercase letters 、 Spaces and numbers 0 To 9 form ( contain 0 and 9)
s Middle number token The number of is in 2 and 100 Between ( contain 2 and 100)
s Medium token Separated by a single space
s At least there is Two Numbers
s Every number in is a Less than 100 Of just Count , Without leading zeros
s No leading or trailing spaces
source : Power button (LeetCode)
Their thinking
A simple idea , Find all the numbers in the sentence , Then compare whether it meets the conditions of the topic one by one .
class Solution:
def areNumbersAscending(self, s: str) -> bool:
num=re.findall(r'\d+',s)
for i in range(1,len(num)):
if int(num[i])<=int(num[i-1]):
return False
return True
边栏推荐
- 【指针】八进制转换为十进制
- Pointer -- eliminate all numbers in the string
- Don't you even look at such a detailed and comprehensive written software test question?
- Cc36 different subsequences
- Functions: Finding Roots of equations
- [HCIA continuous update] working principle of static route and default route
- How to solve the poor sound quality of Vos?
- 基于485总线的评分系统双机实验报告
- Using flask_ Whooshalchemyplus Jieba realizes global search of flask
- Statistics 8th Edition Jia Junping Chapter 3 after class exercises and answer summary
猜你喜欢
移植蜂鸟E203内核至达芬奇pro35T【集创芯来RISC-V杯】(一)
Fundamentals of digital circuit (V) arithmetic operation circuit
王爽汇编语言详细学习笔记二:寄存器
Statistics 8th Edition Jia Junping Chapter 12 summary of knowledge points of multiple linear regression and answers to exercises after class
Es full text index
CSAPP家庭作業答案7 8 9章
ucore lab2 物理内存管理 实验报告
Vysor uses WiFi wireless connection for screen projection_ Operate the mobile phone on the computer_ Wireless debugging -- uniapp native development 008
Express
Fundamentals of digital circuits (II) logic algebra
随机推荐
Function: calculates the number of uppercase letters in a string
Statistics 8th Edition Jia Junping Chapter 10 summary of knowledge points of analysis of variance and answers to exercises after class
1.支付系统
Interview Essentials: what is the mysterious framework asking?
【指针】求二维数组中最大元素的值
Pointer -- eliminate all numbers in the string
Numpy快速上手指南
Fundamentals of digital circuits (II) logic algebra
Statistics 8th Edition Jia Junping Chapter 7 Summary of knowledge points and answers to exercises after class
[pointer] find the value of the largest element in the two-dimensional array
Stc-b learning board buzzer plays music
“Hello IC World”
STC-B学习板蜂鸣器播放音乐2.0
Build your own application based on Google's open source tensorflow object detection API video object recognition system (II)
王爽汇编语言学习详细笔记一:基础知识
[pointer] the array is stored in reverse order and output
指針:最大值、最小值和平均值
What level do 18K test engineers want? Take a look at the interview experience of a 26 year old test engineer
使用 flask_whooshalchemyplus jieba实现flask的全局搜索
Function: find 1-1/2+1/3-1/4+1/5-1/6+1/7-... +1/n