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 28da9a8 commit 14ebc84Copy full SHA for 14ebc84
2042-check-if-numbers-are-ascending-in-a-sentence/2042-check-if-numbers-are-ascending-in-a-sentence.java
@@ -0,0 +1,26 @@
1
+class Solution {
2
+ public boolean areNumbersAscending(String s) {
3
+ String[] sArr = s.split(" ");
4
+ int currentNumber = -1;
5
+ for (int i = 0; i < sArr.length; i++) {
6
+ if (isNumeric(sArr[i])) {
7
+ int number = Integer.parseInt(sArr[i]);
8
+ if (number <= currentNumber) {
9
+ return false;
10
+ } else {
11
+ currentNumber = number;
12
+ }
13
14
15
+ return true;
16
17
+
18
+ public boolean isNumeric(String str) {
19
+ try {
20
+ Integer.parseInt(str);
21
22
+ } catch (NumberFormatException e) {
23
24
25
26
+}
0 commit comments