Code Signal_练习题_All Longest Strings
Given an array of strings, return another array containing all of its longest strings.
Example
For inputArray = ["aba", "aa", "ad", "vcd", "aba"]
, the output should beallLongestStrings(inputArray) = ["aba", "vcd", "aba"]
.
Input/Output
[execution time limit] 4 seconds (py3)
[input] array.string inputArray
A non-empty array.
Guaranteed constraints:
1 ≤ inputArray.length ≤ 10
,1 ≤ inputArray[i].length ≤ 10
.[output] array.string
Array of the longest strings, stored in the same order as in the
inputArray
.
我的解答:
def allLongestStrings(inputArray):
li = []
m = max(inputArray,key=len)
for i in inputArray:
if len(i) == len(m):
li.append(i)
return li
膜拜大佬:
def allLongestStrings(inputArray):
m = max(len(s) for s in inputArray)
r = [s for s in inputArray if len(s) == m]
return r
虽然代码比大佬写的多,但至少想法一样了....
Code Signal_练习题_All Longest Strings的更多相关文章
- 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_练习题_reverseParentheses
You have a string s that consists of English letters, punctuation marks, whitespace characters, and ...
- Code Signal_练习题_commonCharacterCount
Given two strings, find the number of common characters between them. Example For s1 = "aabcc&q ...
- 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_练习题_firstDigit
Find the leftmost digit that occurs in a given string. Example For inputString = "var_1__Int&qu ...
随机推荐
- win32 音视频相关 api
waveInGetNumDevs waveInGetDevCaps waveInOpen waveInGetDevCaps waveInPrepareHeader waveInAddBuffer wa ...
- mysql enterprise backup入门使用
**************************************************************--1.全备******************************** ...
- 设置User Agent
公司的前端要给项目的webview加一个区分,用来区别是iOS端访问.android访问还是在浏览器访问的,说是要加一个User Agent ,前端根据不同信息做适配,和我说来一头雾水,后来经过开发同 ...
- TCP-IP 端口号
FTP服务器的TCP端口号 21 Telnet服务器的TCP端口号 23 TETP(简单文件传输协议)服务器的UDP端口号 69 任何TCP/IP实现所提供的服务都用1-1023之间的端口号 至 ...
- Ubuntu18.04 Redis主从复制
1.下载安装redis http://download.redis.io/releases/ 2.建立一个主7060和一个从7061文件 3.在两个文件夹中建立用于存放数据得db文件和存日志得log文 ...
- “context:include-filter”与“context:exclude-filter”标签作用解释
注意到spring中<context:component-scan>标签中会出现include和exclude的子标签,具体是做什么用的? spring的配置文件与springmvc的配置 ...
- 机器学习实战(一)k-近邻算法
转载请注明源出处:http://www.cnblogs.com/lighten/p/7593656.html 1.原理 本章介绍机器学习实战的第一个算法——k近邻算法(k Nearest Neighb ...
- 【Java并发编程】:并发新特性—塞队列和阻塞栈
阻塞队列 阻塞队列是Java5并发新特性中的内容,阻塞队列的接口是Java.util.concurrent.BlockingQueue,它有多个实现类:ArrayBlockingQueue.Delay ...
- mac 系统安装VM虚拟机打开时报错,提示不是虚拟磁盘的解决方式。
最近刚买的苹果系统,不太会用,装了个虚拟机vmware fusion,好不容易把需要的软件装好,然后不知道是我操作了哪里,今天再次打开虚拟机的时候打不开了,报错提示找不到磁盘文件(虚拟磁盘-00000 ...
- Virtualbox下载与安装步骤
不多说,直接上干货! 本主主要介绍一下如何从官方网站下载正版的 虚拟化 Oracle VM VirtualBox ,以及说明一下去官方下载正版软件的重要性. 一.为了系统的稳定以及数据的安全,建议下载 ...