Find the leftmost digit that occurs in a given string.
Example
inputString = "var_1__Int", the output should be**solution(inputString) = '1'**;inputString = "q2q-q", the output should be**solution(inputString) = '2'**;inputString = "0ss", the output should be**solution(inputString) = '0'**.Input/Output
[execution time limit] 3 seconds (java)
[memory limit] 1 GB
[input] string inputString
A string containing at least one digit.
Guaranteed constraints:
3 ≤ inputString.length ≤ 10.
[output] char
char solution(String inputString) {
String REGEXP_PATTERN_NUMBER = "^[\\\\d]*$";
for(char c : inputString.toCharArray()) {
boolean valid = Pattern.matches(REGEXP_PATTERN_NUMBER, Character.toString(c));
if (valid) return c;
}
return 'a';
}