We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0750faa commit c485a98Copy full SHA for c485a98
Python/check-if-numbers-are-ascending-in-a-sentence.py
@@ -0,0 +1,32 @@
1
+# Time: O(n)
2
+# Space: O(n)
3
+
4
+class Solution(object):
5
+ def areNumbersAscending(self, s):
6
+ """
7
+ :type s: str
8
+ :rtype: bool
9
10
+ prev = curr = -1
11
+ for i, c in enumerate(s):
12
+ if c.isdigit():
13
+ curr = max(curr, 0)*10+int(c)
14
+ continue
15
+ if prev != -1 and curr != -1 and prev >= curr:
16
+ return False
17
+ if curr != -1:
18
+ prev = curr
19
+ curr = -1
20
+ return curr == -1 or prev < curr
21
22
23
24
25
+class Solution2(object):
26
27
28
29
30
31
+ nums = [int(x) for x in s.split() if x.isdigit()]
32
+ return all(nums[i] < nums[i+1] for i in xrange(len(nums)-1))
0 commit comments