Code Signal_练习题_firstDigit
Find the leftmost digit that occurs in a given string.
Example
- For
inputString = "var_1__Int", the output should befirstDigit(inputString) = '1'; - For
inputString = "q2q-q", the output should befirstDigit(inputString) = '2'; - For
inputString = "0ss", the output should befirstDigit(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的更多相关文章
- Code Signal_练习题_digitDegree
Let's define digit degree of some positive integer as the number of times we need to replace this nu ...
- Code Signal_练习题_Knapsack Light
You found two items in a treasure chest! The first item weighs weight1 and is worth value1, and the ...
- Code Signal_练习题_growingPlant
Each day a plant is growing by upSpeed meters. Each night that plant's height decreases by downSpeed ...
- Code Signal_练习题_arrayMaxConsecutiveSum
Given array of integers, find the maximal possible sum of some of its k consecutive elements. Exampl ...
- Code Signal_练习题_differentSymbolsNaive
Given a string, find the number of different characters in it. Example For s = "cabca", th ...
- Code Signal_练习题_extractEachKth
Given array of integers, remove each kth element from it. Example For inputArray = [1, 2, 3, 4, 5, 6 ...
- Code Signal_练习题_stringsRearrangement
Given an array of equal-length strings, check if it is possible to rearrange the strings in such a w ...
- 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) + ...
- Code Signal_练习题_depositProfit
You have deposited a specific amount of money into your bank account. Each year your balance increas ...
随机推荐
- Spring中使用StandardServletMultipartResolver进行文件上传
从Spring3.1开始,Spring提供了两个MultipartResolver的实现用于处理multipart请求,分别是:CommonsMultipartResolver和StandardSer ...
- flask框架1
说flask框架之前,必须得提一下web框架,他的作用是为了利用互联网交流工作文档,我们为什么要使用框架,因为框架的稳定性和可扩展性强并且可以降低开发难度,提高开发效率.总的来说就是避免做无用功,重复 ...
- SpringBoot从入门到逆天(1)
1.SpringBoot是什么? <1>为Sping开发提供一个更 快捷更广泛的入门体验. <2>开箱即用,不合适时特可以快速抛弃. <3>提供一系列大型项目常用的 ...
- centOS7.10 KDE桌面字体设置推荐
安装完centOS7.10的KDE桌面后,第一次使用觉得字体太难看了,特别是终端,看着很难受,调整多次后觉得如下设置舒服很多,分享出来以供参考. 其中等宽字 这样整体看着就会舒服很多 ******** ...
- 【xsy2274】 平均值 线段树
题目大意:给你一个长度为$n$的序列$a$,请你求: $\sum\limits_{l=1}^{n}\sum\limits_{r=l}^{n}\dfrac{mex(a_l,a_{l+1},...,a_r ...
- Storm官方提供的trident单词计数的例子
上代码: public class TridentWordCount { public static class Split extends BaseFunction { @Override publ ...
- Storm中的定时任务
1.全局定时器 import java.util.Map; import backtype.storm.Config; import backtype.storm.Constants; import ...
- python多线程-Semaphore(信号对象)
Semaphore(value=1) Semaphore对象内部管理一个计数器,该计数器由每个acquire()调用递减,并由每个release()调用递增.计数器永远不会低于零,当acquire() ...
- (转)实现一个cache装饰器,实现过期可清除功能
原文:http://www.cnblogs.com/JerryZao/p/9574927.html http://blog.51cto.com/11281400/2107790-----装饰器应用练习 ...
- Java模式—简单工厂模式
简单工厂模式:是由一个工厂对象决定创建出哪一种产品类的实例,简单工厂模式是工厂模式家族中最简单实用的模式. 目的:为创建对象提供过渡接口,以便将创建对象的具体过程屏蔽隔离起来,达到提高灵活性的目的. ...