当前位置:网站首页>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
边栏推荐
- Interview Essentials: what is the mysterious framework asking?
- Global and Chinese market of pinhole glossmeter 2022-2028: Research Report on technology, participants, trends, market size and share
- Fundamentals of digital circuits (I) number system and code system
- flask实现强制登陆
- Oracle foundation and system table
- Install and run tensorflow object detection API video object recognition system of Google open source
- 5 minutes to master machine learning iris logical regression classification
- Summary of thread implementation
- Logstack introduction and deployment -- elasticstack (elk) work notes 019
- ByteDance ten years of experience, old bird, took more than half a year to sort out the software test interview questions
猜你喜欢
数字电路基础(四) 数据分配器、数据选择器和数值比较器
STC-B学习板蜂鸣器播放音乐
What is the transaction of MySQL? What is dirty reading and what is unreal reading? Not repeatable?
Logstack introduction and deployment -- elasticstack (elk) work notes 019
Fundamentals of digital circuit (V) arithmetic operation circuit
数据库多表链接的查询方式
C language do while loop classic Level 2 questions
STC-B学习板蜂鸣器播放音乐2.0
What is an index in MySQL? What kinds of indexes are commonly used? Under what circumstances will the index fail?
Statistics 8th Edition Jia Junping Chapter 5 probability and probability distribution
随机推荐
“Hello IC World”
Database monitoring SQL execution
Statistics 8th Edition Jia Junping Chapter 1 after class exercises and answers summary
MySQL中什么是索引?常用的索引有哪些种类?索引在什么情况下会失效?
【指针】求二维数组中最大元素的值
Don't you even look at such a detailed and comprehensive written software test question?
How to solve the poor sound quality of Vos?
指針:最大值、最小值和平均值
ES全文索引
"If life is just like the first sight" -- risc-v
王爽汇编语言详细学习笔记二:寄存器
[HCIA continuous update] advanced features of routing
ucore lab2 物理内存管理 实验报告
Transplant hummingbird e203 core to Da Vinci pro35t [Jichuang xinlai risc-v Cup] (I)
Global and Chinese markets of electronic grade hexafluorobutadiene (C4F6) 2022-2028: Research Report on technology, participants, trends, market size and share
C language do while loop classic Level 2 questions
[pointer] the array is stored in reverse order and output
Quaternion -- basic concepts (Reprint)
Statistics, 8th Edition, Jia Junping, Chapter VIII, summary of knowledge points of hypothesis test and answers to exercises after class
Fundamentals of digital circuits (I) number system and code system