Skip to content

Commit a32a124

Browse files
authored
Create Check if Numbers Are Ascending in a Sentence.java
1 parent 043a5f8 commit a32a124

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public boolean areNumbersAscending(String s) {
3+
int prevValue = Integer.MIN_VALUE;
4+
for (int i = 0; i < s.length(); ) {
5+
if (Character.isDigit(s.charAt(i))) {
6+
int currNum = 0;
7+
while (i < s.length() && Character.isDigit(s.charAt(i))) {
8+
currNum = currNum * 10 + Character.getNumericValue(s.charAt(i++));
9+
}
10+
if (currNum <= prevValue) {
11+
return false;
12+
}
13+
prevValue = currNum;
14+
}
15+
i++;
16+
}
17+
return true;
18+
}
19+
}

0 commit comments

Comments
 (0)