|
| 1 | +<h2><a href="https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/?envType=problem-list-v2&envId=string">2042. Check if Numbers Are Ascending in a Sentence</a></h2><h3>Easy</h3><hr><p>A sentence is a list of <strong>tokens</strong> separated by a <strong>single</strong> space with no leading or trailing spaces. Every token is either a <strong>positive number</strong> consisting of digits <code>0-9</code> with no leading zeros, or a <strong>word</strong> consisting of lowercase English letters.</p> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <li>For example, <code>"a puppy has 2 eyes 4 legs"</code> is a sentence with seven tokens: <code>"2"</code> and <code>"4"</code> are numbers and the other tokens such as <code>"puppy"</code> are words.</li> |
| 5 | +</ul> |
| 6 | + |
| 7 | +<p>Given a string <code>s</code> representing a sentence, you need to check if <strong>all</strong> the numbers in <code>s</code> are <strong>strictly increasing</strong> from left to right (i.e., other than the last number, <strong>each</strong> number is <strong>strictly smaller</strong> than the number on its <strong>right</strong> in <code>s</code>).</p> |
| 8 | + |
| 9 | +<p>Return <code>true</code><em> if so, or </em><code>false</code><em> otherwise</em>.</p> |
| 10 | + |
| 11 | +<p> </p> |
| 12 | +<p><strong class="example">Example 1:</strong></p> |
| 13 | +<img alt="example-1" src="https://assets.leetcode.com/uploads/2021/09/30/example1.png" style="width: 637px; height: 48px;" /> |
| 14 | +<pre> |
| 15 | +<strong>Input:</strong> s = "1 box has 3 blue 4 red 6 green and 12 yellow marbles" |
| 16 | +<strong>Output:</strong> true |
| 17 | +<strong>Explanation:</strong> The numbers in s are: 1, 3, 4, 6, 12. |
| 18 | +They are strictly increasing from left to right: 1 < 3 < 4 < 6 < 12. |
| 19 | +</pre> |
| 20 | + |
| 21 | +<p><strong class="example">Example 2:</strong></p> |
| 22 | + |
| 23 | +<pre> |
| 24 | +<strong>Input:</strong> s = "hello world 5 x 5" |
| 25 | +<strong>Output:</strong> false |
| 26 | +<strong>Explanation:</strong> The numbers in s are: <u><strong>5</strong></u>, <strong><u>5</u></strong>. They are not strictly increasing. |
| 27 | +</pre> |
| 28 | + |
| 29 | +<p><strong class="example">Example 3:</strong></p> |
| 30 | +<img alt="example-3" src="https://assets.leetcode.com/uploads/2021/09/30/example3.png" style="width: 794px; height: 48px;" /> |
| 31 | +<pre> |
| 32 | +<strong>Input:</strong> s = "sunset is at 7 51 pm overnight lows will be in the low 50 and 60 s" |
| 33 | +<strong>Output:</strong> false |
| 34 | +<strong>Explanation:</strong> The numbers in s are: 7, <u><strong>51</strong></u>, <u><strong>50</strong></u>, 60. They are not strictly increasing. |
| 35 | +</pre> |
| 36 | + |
| 37 | +<p> </p> |
| 38 | +<p><strong>Constraints:</strong></p> |
| 39 | + |
| 40 | +<ul> |
| 41 | + <li><code>3 <= s.length <= 200</code></li> |
| 42 | + <li><code>s</code> consists of lowercase English letters, spaces, and digits from <code>0</code> to <code>9</code>, inclusive.</li> |
| 43 | + <li>The number of tokens in <code>s</code> is between <code>2</code> and <code>100</code>, inclusive.</li> |
| 44 | + <li>The tokens in <code>s</code> are separated by a single space.</li> |
| 45 | + <li>There are at least <strong>two</strong> numbers in <code>s</code>.</li> |
| 46 | + <li>Each number in <code>s</code> is a <strong>positive</strong> number <strong>less</strong> than <code>100</code>, with no leading zeros.</li> |
| 47 | + <li><code>s</code> contains no leading or trailing spaces.</li> |
| 48 | +</ul> |
0 commit comments