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 ...
随机推荐
- updateByPrimaryKey 和 updateByPrimaryKeySelective
1. 数据库记录 2. updateByPrimaryKey Preparing: UPDATE t_token_info SET entity_id = ?,entity_type = ?,time ...
- flask框架~简易编写
flaks框架: 先导报 from flask import Flask 重定向模块:redirect url_for是简易寻址跳转 jsonify强转为json格式 建立flask对象:app = ...
- Oracle 11g安装时针对不同操作系统所需的依赖包查询地址
http://docs.oracle.com/cd/E11882_01/install.112/e24326/ 点击连接,出现页面,往下滑动:)
- 通过XMLHttpRequest和jQuery两种方式实现ajax
一.XMLHttpRequest实现获取数据 不使用jQuery实现页面不刷新获取内容的方式,我们这里采用XMLHttpRequest原生代码实现:js代码如下: //1.获取a节点,并为其添加Onc ...
- ElasticSearch入门3: Spring Boot集成ElasticSearch
第一步:创建项目elasticsearch 编写pom文件 <?xml version="1.0" encoding="UTF-8"?> <p ...
- 分析NonfairSync加锁/解锁过程
类继承关系: NonfairSync => Sync => AbstractQueuedSynchronizer 类NonfairSync final void lock() { if ( ...
- vue.js过渡效果之--javascript钩子
写在前面 姊妹篇 vue.js之过渡效果-css.今天一篇博文阅读量破300,心里还是有点小激动的.没错,我就是这么容易满足(害羞).这个数据可能连大牛一篇文章阅读量的零头都没有,但这却是我个人的一 ...
- StreamSets学习系列之StreamSets的Create New Pipeline(图文详解)
不多说,直接上干货! 前期博客 StreamSets学习系列之StreamSets支持多种安装方式[Core Tarball.Cloudera Parcel .Full Tarball .Full R ...
- 解决IDEA中进行maven install报:系统资源不足的问题
一.背景 最近在idea中使用maven对公司的项目进行install的时候老是出现系统资源不足的问题导致install失败,在网上搜索也没找到很好的答案,自己不断摸索,最终在idea的配置里面找到了 ...
- freemark null处理
以下引用官方描述: 引用The FreeMarker template language doesn't know the Java language null at all. It doesn't ...