1796.字符串中第二大的数字

给你一个混合字符串 s ,请你返回 s第二大 的数字,如果不存在第二大的数字,请你返回 -1

混合字符串 由小写英文字母和数字组成。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Solution {
public int secondHighest(String s) {
char[] str=s.toCharArray();
int maxMax=-1;
int minMax=-1;
for(int i=0;i<str.length;i++){
if(!Character.isDigit(str[i])){
continue;
}
int temp=str[i]-'0';
if(temp>maxMax){
minMax=maxMax;
maxMax=temp;
}else if(temp>minMax&&temp<maxMax){
minMax=temp;
}
}
return minMax;
}
}