2496. Maximum Value of a String in an Array

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Solution {
public int maximumValue(String[] strs) {
int maxValue = 0;
for (String str : strs) {
boolean isNum = true;
int value = 0;
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (c >= '0' && c <= '9') {
value = value * 10 + (c - '0');
} else {
isNum = false;
break;
}
}

maxValue = Math.max(maxValue, isNum ? value : str.length());
}

return maxValue;
}
}

References

2496. Maximum Value of a String in an Array