CodeSignal/Arcade
CodeSignal [35/60] firstDigit
벤진[Benzene]
2020. 5. 25. 01:15
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]