-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAreNumbersAscending.java
More file actions
37 lines (34 loc) · 1009 Bytes
/
AreNumbersAscending.java
File metadata and controls
37 lines (34 loc) · 1009 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* 2042 检查句子中的数字是否递增
*/
public class AreNumbersAscending {
public boolean areNumbersAscending(String s) {
int pre = 0, cur;
int left=0, right=0;
while(left<s.length()){
char c = s.charAt(left);
if(('0'<=c && c<='9') && ((left==0) ||
(s.charAt(left-1)<'0' || s.charAt(left-1)>'9'))){
right = left+1;
while(right<s.length()){
char t = s.charAt(right);
if(t<'0' || t>'9'){
break;
}else{
right++;
}
}
cur = Integer.parseInt(s.substring(left, right));
if(cur<=pre){
return false;
}else{
pre = cur;
left = right;
}
}else{
left++;
}
}
return true;
}
}