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'.

我的解答:

def firstDigit(inputString):
return [i for i in inputString if i.isdigit()][0]
def firstDigit(inputString):
for i in inputString:
if i.isdigit():
return i

膜拜大佬

Code Signal_练习题_firstDigit的更多相关文章

  1. Code Signal_练习题_digitDegree

    Let's define digit degree of some positive integer as the number of times we need to replace this nu ...

  2. Code Signal_练习题_Knapsack Light

    You found two items in a treasure chest! The first item weighs weight1 and is worth value1, and the ...

  3. Code Signal_练习题_growingPlant

    Each day a plant is growing by upSpeed meters. Each night that plant's height decreases by downSpeed ...

  4. Code Signal_练习题_arrayMaxConsecutiveSum

    Given array of integers, find the maximal possible sum of some of its k consecutive elements. Exampl ...

  5. Code Signal_练习题_differentSymbolsNaive

    Given a string, find the number of different characters in it. Example For s = "cabca", th ...

  6. Code Signal_练习题_extractEachKth

    Given array of integers, remove each kth element from it. Example For inputArray = [1, 2, 3, 4, 5, 6 ...

  7. Code Signal_练习题_stringsRearrangement

    Given an array of equal-length strings, check if it is possible to rearrange the strings in such a w ...

  8. Code Signal_练习题_absoluteValuesSumMinimization

    Given a sorted array of integers a, find an integer x from a such that the value of abs(a[0] - x) + ...

  9. Code Signal_练习题_depositProfit

    You have deposited a specific amount of money into your bank account. Each year your balance increas ...

随机推荐

  1. 使用python及工具包进行简单的验证码识别

    相信大家利用 Python 写的爬虫应该遇到过要输入验证码的尴尬局面,又或者写了个自动填充表单的小程序,结果就卡在了验证码上. 在ctf中有⼀一些题⽬目,本身有弱验证码识别绕过,那么我们怎么解决呢? ...

  2. SpringBoot启动过程分析

    我们知道,SpringBoot程序的启动很简单,代码如下: @SpringBootApplication public class Application { public static void m ...

  3. django操作memcached

    1.首先需要在settings.py中配置好缓存 CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.memcached.Me ...

  4. MethodImplOptions.Synchronized的一点讨论

    Review代码发现有一个方法加了[MethodImpl(MethodImplOptions.Synchronized)] 属性,这个属性的目的,从名字上就可以看出,是要对所有线程进行同步执行. 对方 ...

  5. Java生成某段时间内的随机时间

    上代码: import java.text.SimpleDateFormat; import java.util.Date; public class DateUtil { /** * 生成随机时间 ...

  6. / | \ # $ ^ & *这些符号怎么读

    供参考: /: slash或forward slash 英 [slæʃ] |: vertical bar或pipe #: number sign或pound sign \: backslash 英 [ ...

  7. Java中的日志管理

    日志是应用程序运行中不可缺少的一部分,JAVA中有很多已经成熟的方案,尽管记录日志是应用开发中并不可少的功能,在 JDK 的最初版本中并不包含日志记录相关的 API 和实现.相关的 API(java. ...

  8. html中引入调用另一个公用html模板文件的方法

    html中引入调用另一个公用html模板文件的方法 https://www.w3h5.com/post/53.html 这里我使用jquery的方法 <body> <div id=& ...

  9. Android面试题(1)

    1.  Java语言基本数据类型有哪些?分别占用的内存空间是多少? 答: byte(1字节),boolean(1字节),char(2字节),short(2字节),int(4字节),float(4字节) ...

  10. es-01-简介

    1, 基于lucene的实时搜索软件 分布式的restful风格的搜索和数据分析引擎, 2, 和kibana, logstash 构成 elk生态圈 es: 数据存储和查询 kibana: 可视化 l ...