Class Solution
java.lang.Object
g2001_2100.s2042_check_if_numbers_are_ascending_in_a_sentence.Solution
2042 - Check if Numbers Are Ascending in a Sentence.<p>Easy</p>
<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>
<ul>
<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>
</ul>
<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>
<p>Return <code>true</code> <em>if so, or</em> <code>false</code> <em>otherwise</em>.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/09/30/example1.png" alt="example-1" /></p>
<p><strong>Input:</strong> s = “1 box has 3 blue 4 red 6 green and 12 yellow marbles”</p>
<p><strong>Output:</strong> true</p>
<p><strong>Explanation:</strong> The numbers in s are: 1, 3, 4, 6, 12. They are strictly increasing from left to right: 1 < 3 < 4 < 6 < 12.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s = “hello world 5 x 5”</p>
<p><strong>Output:</strong> false</p>
<p><strong>Explanation:</strong> The numbers in s are: <strong>5</strong> , <strong>5</strong>. They are not strictly increasing.</p>
<p><strong>Example 3:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/09/30/example3.png" alt="example-3" /></p>
<p><strong>Input:</strong> s = “sunset is at 7 51 pm overnight lows will be in the low 50 and 60 s”</p>
<p><strong>Output:</strong> false</p>
<p><strong>Explanation:</strong> The numbers in s are: 7, <strong>51</strong> , <strong>50</strong> , 60. They are not strictly increasing.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>3 <= s.length <= 200</code></li>
<li><code>s</code> consists of lowercase English letters, spaces, and digits from <code>0</code> to <code>9</code>, inclusive.</li>
<li>The number of tokens in <code>s</code> is between <code>2</code> and <code>100</code>, inclusive.</li>
<li>The tokens in <code>s</code> are separated by a single space.</li>
<li>There are at least <strong>two</strong> numbers in <code>s</code>.</li>
<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>
<li><code>s</code> contains no leading or trailing spaces.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
areNumbersAscending
-