#2042

Check if Numbers Are Ascending in a Sentence

newbie · 255 · lc easy +19 · verified · 72.9% accepted · 697 likes · top 83%

Description

A sentence string s contains space-separated tokens, each of which is either a non-negative integer (no leading zeros) or a lowercase word. Check whether all numeric tokens appear in strictly increasing order from left to right. Return true if they do, false otherwise.

Example 1:

Input: s = "1 box has 3 blue 4 red 6 green and 12 yellow marbles"
Output: true
Explanation: 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: false
Explanation: The numbers in s are: 5, 5. They are not strictly increasing.

Example 3:

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

Code

1
2
3