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 ...
随机推荐
- 防止sql注入的小函数 以及一些小验证
function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialch ...
- Java并发编程总结1——线程状态、synchronized
以下内容主要总结自<Java多线程编程核心技术>,不定时补充更新. 一.线程的状态 Java中,线程的状态有以下6类:NEW, RUNNABLE, BLOCKED, WAITING, TI ...
- MySQL修改root密码的方法总结
方法1: 用SET PASSWORD命令 mysql -u root mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass ...
- 调用notify()后,当前线程执行完synchronized块中的所有代码才会释放锁
package com.pinnet.test; public class Demo { public static void main(String[] args) { Demo demo = ne ...
- [原创]K8 CMS GoastGuard 密码解密工具
工具: K8 CMS GoastGuard PASS Decrypt编译: VS2012 C# (.NET Framework v4.5)组织: K8搞基大队[K8team]作者: K8拉登哥哥博客 ...
- FireFox浏览器-xpath快速定位插件:Xpath Checker
FireFox浏览器-xpath快速定位插件:Xpath Checker 插件截图:
- ES6 模块定义 export 与 import
一般导出 export math.js export function* getFibo() { let a = 1; let b = 1; yield a; yield b; while (true ...
- MySQL笔记(5)---索引与算法
1.前言 本章记录MySQL中的索引机制,了解索引可以让数据库更快.索引太多会造成性能损耗,索引太少肯定查询效率不高. 2.InnoDB存储引擎所有概述 InnoDB中常见的索引有: B+树索引 全文 ...
- 全网最详细的启动或格式化zkfc时出现java.net.NoRouteToHostException: No route to host ... Will not attempt to authenticate using SASL (unknown error)错误的解决办法(图文详解)
不多说,直接上干货! 全网最详细的启动zkfc进程时,出现INFO zookeeper.ClientCnxn: Opening socket connection to server***/192.1 ...
- 高可用Hadoop平台-启航
1.概述 在上篇博客中,我们搭建了<配置高可用Hadoop平台>,接下来我们就可以驾着Hadoop这艘巨轮在大数据的海洋中遨游了.工欲善其事,必先利其器.是的,没错:我们开发需要有开发工具 ...