最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

Leetcode 2042. Check if Numbers Are Ascending in a Sentence

2023-02-26 08:51 作者:您是打尖兒還是住店呢  | 我要投稿

A sentence is a list of?tokens?separated by a?single?space with no leading or trailing spaces. Every token is either a?positive number?consisting of digits?0-9?with no leading zeros, or a?word?consisting of lowercase English letters.

  • For example,?"a puppy has 2 eyes 4 legs"?is a sentence with seven tokens:?"2"?and?"4"?are numbers and the other tokens such as?"puppy"?are words.

Given a string?s?representing a sentence, you need to check if?all?the numbers in?s?are?strictly increasing?from left to right (i.e., other than the last number,?each?number is?strictly smaller?than the number on its?right?in?s).

Return?true?if so, or?false?otherwise.

?

Example 1:

example-1

Input: s = "1 box has 3 blue 4 red 6 green and 12 yellow marbles"Output: trueExplanation: The numbers in s are: 1, 3, 4, 6, 12. They are strictly increasing from left to right: 1 < 3 < 4 < 6 < 12.

Example 2:

Input: s = "hello world 5 x 5"Output: falseExplanation: The numbers in s are: 5, 5. They are not strictly increasing.

Example 3:

example-3

Input: s = "sunset is at 7 51 pm overnight lows will be in the low 50 and 60 s"Output: falseExplanation: The numbers in s are: 7, 51, 50, 60. They are not strictly increasing.

?

Constraints:

  • 3 <= s.length <= 200

  • s?consists of lowercase English letters, spaces, and digits from?0?to?9, inclusive.

  • The number of tokens in?s?is between?2?and?100, inclusive.

  • The tokens in?s?are separated by a single space.

  • There are at least?two?numbers in?s.

  • Each number in?s?is a?positive?number?less?than?100, with no leading zeros.

  • s?contains no leading or trailing spaces.

Easy 題目,主要是先放到數(shù)組中,然后數(shù)組判斷是否嚴(yán)格遞增即可;

Runtime:?3 ms, faster than?55.79%?of?Java?online submissions for?Check if Numbers Are Ascending in a Sentence.

Memory Usage:?40.7 MB, less than?61.87%?of?Java?online submissions for?Check if Numbers Are Ascending in a Sentence.


Leetcode 2042. Check if Numbers Are Ascending in a Sentence的評論 (共 條)

分享到微博請遵守國家法律
奈曼旗| 上饶市| 安庆市| 玉田县| 长岭县| 东平县| 奉节县| 博野县| 六安市| 克山县| 东乌珠穆沁旗| 颍上县| 依兰县| 深泽县| 佳木斯市| 洞头县| 牙克石市| 淮北市| 措勤县| 天等县| 永定县| 恭城| 金华市| 天镇县| 定远县| 名山县| 建瓯市| 芷江| 罗田县| 体育| 石河子市| 株洲市| 任丘市| 密云县| 曲松县| 安徽省| 个旧市| 雅安市| 阆中市| 阜平县| 元阳县|