LeetCode solutions

2168. Check if Numbers Are Ascending in a Sentence

My accepted Python solution to LeetCode problem 2168, Check if Numbers Are Ascending in a Sentence, running in 0ms.

  • Difficulty: Easy
  • Python
  • Runtime 0ms
  • Memory 17.3MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 17.3MB, accepted 2025-12-31.

python
class Solution:
    def areNumbersAscending(self, s: str) -> bool:
        prev = -1
        for word in s.split():
            if word.isdigit():
                num = int(word)
                if num <= prev:
                    return False
                prev = num
        return True

Source