Leetcode Problem 2042. Check if Numbers Are Ascending in a Sentence

2042. Check if Numbers Are Ascending in a Sentence

Leetcode Solutions

Iterative Parsing and Comparison

  1. Initialize a variable last_number to -1 to store the last number found.
  2. Split the sentence s into tokens based on spaces.
  3. Iterate over each token in the sentence. a. Check if the token is a number. b. If it is a number, parse it to an integer. c. Compare the parsed number with last_number. d. If the number is less than or equal to last_number, return false. e. Update last_number with the current number.
  4. After the loop, return true as all numbers are strictly increasing.
UML Thumbnail

Regex Matching and Incremental Check

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...