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 ...
随机推荐
- 浏览器特权域XSS漏洞
导语:科普什么是浏览器特权域XSS,可以用来干什么? 作者:天析 团队:Arctic Shell 为什么科普这个? 今天在群里看到有表姐说这个,然后恰好又有学姐在问什么是特权域XSS,于是就来说说这个 ...
- python并发编程之进程池,线程池concurrent.futures
进程池与线程池 在刚开始学多进程或多线程时,我们迫不及待地基于多进程或多线程实现并发的套接字通信,然而这种实现方式的致命缺陷是:服务的开启的进程数或线程数都会随着并发的客户端数目地增多而增多, 这会对 ...
- 使用Express构建RESTful API
RESTful服务 REST(Representational State Transfer)的意思是表征状态转移,它是一种基于HTTP协议的网络应用接口风格,充分利用HTTP的方法实现统一风格接口的 ...
- cpu负载的探讨 (转)
文章出处:http://blog.chinaunix.net/uid-12693781-id-368837.html 摘要:确定cpu的负载的定义,帮助管理员设置cpu负载阀值,推测可能的导致cpu负 ...
- SSH框架整合详细分析【执行流程】
struts1和spring有两种整合的方法 一种是action和spring bean映射:一种是将action交给spring初始化 第一种方式:访问.do的URL->tomcat接收到r ...
- JVM(一)JVM的概述与运行流程
1.基本概念 JVM和普通虚拟机: 大家常用的两种虚拟机是VMWare和Visual Box,用来操作cpu指令. JVM是程序自己独立的运行环境,对堆栈.寄存器.字符码指令等操作. Java.JRu ...
- Android面试题(1)
1. Java语言基本数据类型有哪些?分别占用的内存空间是多少? 答: byte(1字节),boolean(1字节),char(2字节),short(2字节),int(4字节),float(4字节) ...
- 磁盘分区(20G升50G)
不多说,直接上干货! 本博文的主要内容有 .磁盘分区的概述 .常用的磁盘管理工具 ./下分5G,给/home扩容 .系统自带的fdisk和parted这两款工具 .磁盘空间管理 前言 ...
- Gen类的字符串操作
public void t(String d){ final String str = "b"; String s = "a"+"c"+st ...
- Visual Studio自带的的Developer Command Prompt对话框
简单了解Visual Studio的Developer Command Prompt VS2008的命令为:Visual Studio 2008 Command Prompt 目录是: 其详细信息如下 ...