반응형

Find the leftmost digit that occurs in a given string.


Example


For inputString = "var_1__Int", the output should be

firstDigit(inputString) = '1';

For inputString = "q2q-q", the output should be

firstDigit(inputString) = '2';

For inputString = "0ss", the output should be

firstDigit(inputString) = '0'.


code>>


char firstDigit(std::string inputString) {

std::regex r("[^0-9]");

return regex_replace(inputString, r, "").c_str()[0];

}

반응형

'알고리즘 > codefights' 카테고리의 다른 글

37>arrayMaxConsecutiveSum  (0) 2017.08.07
36>differentSymbolsNaive  (0) 2017.07.31
34>extractEachKth  (0) 2017.07.31
33>stringsRearrangement  (0) 2017.07.31
32>absoluteValuesSumMinimization  (0) 2017.07.08

+ Recent posts