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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 0ms, memory 17.3MB, accepted 2025-12-31.
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