当前位置:网站首页>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 -- output all characters in the string in reverse order
- CSAPP家庭作业答案7 8 9章
- ES全文索引
- c语言学习总结(上)(更新中)
- 函数:求1-1/2+1/3-1/4+1/5-1/6+1/7-…+1/n
- 后台登录系统,JDBC连接数据库,做小案例练习
- Build your own application based on Google's open source tensorflow object detection API video object recognition system (II)
- China's county life record: go upstairs to the Internet, go downstairs' code the Great Wall '
- The salary of testers is polarized. How to become an automated test with a monthly salary of 20K?
猜你喜欢

Get started with Matplotlib drawing

150 common interview questions for software testing in large factories. Serious thinking is very valuable for your interview

servlet中 servlet context与 session与 request三个对象的常用方法和存放数据的作用域。

Build your own application based on Google's open source tensorflow object detection API video object recognition system (II)

Login the system in the background, connect the database with JDBC, and do small case exercises

The salary of testers is polarized. How to become an automated test with a monthly salary of 20K?

The common methods of servlet context, session and request objects and the scope of storing data in servlet.

About the garbled code problem of superstar script

Statistics 8th Edition Jia Junping Chapter 4 Summary and after class exercise answers

Stc-b learning board buzzer plays music 2.0
随机推荐
Global and Chinese markets of electronic grade hexafluorobutadiene (C4F6) 2022-2028: Research Report on technology, participants, trends, market size and share
Cadence physical library lef file syntax learning [continuous update]
[pointer] octal to decimal
What are the business processes and differences of the three basic business modes of Vos: direct dial, callback and semi direct dial?
Database monitoring SQL execution
Oracle foundation and system table
CSAPP homework answers chapter 789
Transplant hummingbird e203 core to Da Vinci pro35t [Jichuang xinlai risc-v Cup] (I)
Global and Chinese markets of MPV ACC ECU 2022-2028: Research Report on technology, participants, trends, market size and share
STC-B学习板蜂鸣器播放音乐2.0
What is an index in MySQL? What kinds of indexes are commonly used? Under what circumstances will the index fail?
函数:求两个正数的最大公约数和最小公倍
关于交换a和b的值的四种方法
Report on the double computer experiment of scoring system based on 485 bus
Fundamentals of digital circuits (III) encoder and decoder
Why can swing implement a form program by inheriting the JFrame class?
数字电路基础(五)算术运算电路
The common methods of servlet context, session and request objects and the scope of storing data in servlet.
150 common interview questions for software testing in large factories. Serious thinking is very valuable for your interview
Statistics 8th Edition Jia Junping Chapter 1 after class exercises and answers summary