[LeetCode]#2042. Check if Numbers Are Ascending in a Sentence

Input: s = "1 box has 3 blue 4 red 6 green and 12 yellow marbles"
Output: true
Explanation: The numbers in s are: 1, 3, 4, 6, 12.
They are strictly increasing from left to right: 1 < 3 < 4 < 6 < 12.
class Solution:
def areNumbersAscending(self, s):
ans=[]
for s in s.split():
if not s.isdecimal():
continue
else:
ans.append(int(s))
#sans=sorted(ans)
for i in range(len(ans)-1):
if ans[i]>=ans[i+1]:
return False

return True

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store