Problem:
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'.
-Summary-
1. isdigit() 함수를 이용하여 char 하나하나 비교후, if we found a 'True' value, then we return the character. (which is digit)
사람들이 작성한 답을 보니, Try and Except로 푼 답도 있었다.
for i in s:
try:
x=int(i)
return i
except:
continue
모든 문제에 대한 저작권은 CodeSignal 회사에 있습니다. [Copyright © 2020 BrainFights Inc. All rights reserved]
'CodeSignal > Arcade' 카테고리의 다른 글
CodeSignal [37/60] arrayMaxConsecutiveSum (0) | 2020.05.25 |
---|---|
CodeSignal [36/60] differentSymbolsNaive (0) | 2020.05.25 |
CodeSignal [34/60] extractEachKth (0) | 2020.05.24 |
CodeSignal [33/60] stringsRearrangement (1) | 2020.05.23 |
CodeSignal [32/60] absoluteValuesSumMinimization (0) | 2020.05.22 |
댓글